function inputclear (td,check){
	if(td.id=="inputcpemail"){
		if(check==true && td.value=='E-mail'){
			td.value=''	
		}
		else if(check==false && td.value==''){
			td.value='E-mail'	
		}
	}
	else if(td.id=="inputcppassword"){
		if(check==true && td.value=='Password'){
			td.value=''	
		}
		else if(check==false && td.value==''){
			td.value='Password'	
		}
	}


}



matchColumns=function(){ 


     var divs,contDivs,maxHeight,divHeight,d; 

	

     // get all <div> elements in the document 



     divs=document.getElementsByTagName('div'); 



     contDivs=[]; 



     // initialize maximum height value 



     maxHeight=0; 



     // iterate over all <div> elements in the document 



     for(var i=0;i<divs.length;i++){ 



          // make collection with <div> elements with class attribute 'container' 



          if(/\bcolumn\b/.test(divs[i].className)){ 



                d=divs[i]; 



                contDivs[contDivs.length]=d; 



                // determine height for <div> element 



                if(d.offsetHeight){ 



                     divHeight=d.offsetHeight; 					



                } 



                else if(d.style.pixelHeight){ 



                     divHeight=d.style.pixelHeight;					 



                } 



                // calculate maximum height 



                maxHeight=Math.max(maxHeight,divHeight); 


          } 



     } 



     // assign maximum height value to all of container <div> elements 



     for(var i=0;i<contDivs.length;i++){ 



          contDivs[i].style.height=maxHeight + "px"; 



     } 



} 



// Runs the script when page loads 



window.onload=function(){ 



     if(document.getElementsByTagName){ 



          matchColumns();			 



     } 



} 





function mainmenu(td){

	var string=td.id

	if(string.indexOf('act')==-1)

	{

		td.id=string+'act';

	}

	else{

		td.id=string.replace('act','');	

	}



}



function categorycheck(check,td)

{



	var x = document.forms.communityresource

	x["existingcat"].disabled = !check

	x["newcat"].disabled = check

	

	if(td.value=='newcat'){

		x['newcat'].value=''

		x['existingcat'].value='empty'

	}

	if(td.value=='existingcat'){

		x['newcat'].value='Suggest a new category...'

	}



}



function searchboxclear (td,check){

	if(check==true && td.value=='Search essays...'){

		td.value=''	

	}

	if(check==false && td.value==''){

		td.value='Search essays...'	

	}

}



function price() 

{

	var level=document.level.level.value

	

	if(document.getElementById("juniorhigh").style.display=="block") 

	{

		document.getElementById("juniorhigh").style.display="none"; 

	}

	if(document.getElementById("highschool").style.display=="block") 

	{

		document.getElementById("highschool").style.display="none"; 

	}

	if(document.getElementById("collegeyear1").style.display=="block") 

	{

		document.getElementById("collegeyear1").style.display="none"; 

	}

	if(document.getElementById("collegeyear2").style.display=="block") 

	{

		document.getElementById("collegeyear2").style.display="none"; 

	}

	if(document.getElementById("collegeyear3").style.display=="block") 

	{

		document.getElementById("collegeyear3").style.display="none"; 

	}

	if(document.getElementById("collegeyear4").style.display=="block") 

	{

		document.getElementById("collegeyear4").style.display="none"; 

	}

	

	if(document.getElementById("graduate").style.display=="block") 

	{

		document.getElementById("graduate").style.display="none"; 

	}

	if(document.getElementById("phd").style.display=="block") 

	{

		document.getElementById("phd").style.display="none"; 

	}

	if(document.getElementById("phd").style.display=="block") 

	{

		document.getElementById("phd").style.display="none"; 

	}

	if(document.getElementById("professional").style.display=="block") 

	{

		document.getElementById("professional").style.display="none"; 

	}



	if(level!==""){

	document.getElementById(level).style.display="block"

	}



}



function project_type()

{

	if(document.getElementById("powerpoint").selected)

	{

	document.getElementById("pages").innerHTML="Number of slides"

	} 



	if(document.getElementById("quantitative_project_accounting").selected)

	{

	document.getElementById("pages").innerHTML="Number of problems:"

	} 

	

	if(document.getElementById("quantitative_project_finance").selected)

	{

	document.getElementById("pages").innerHTML="Number of problems:"

	} 



	if(document.getElementById("quantitative_project_statistics").selected)

	{

	document.getElementById("pages").innerHTML="Number of problems:"

	} 





	if(!document.getElementById("quantitative_project_statistics").selected && !document.getElementById("quantitative_project_finance").selected && !document.getElementById("quantitative_project_accounting").selected && !document.getElementById("powerpoint").selected)

	{

	document.getElementById("pages").innerHTML="Number of pages:"

	} 

}

function rate_quote()

{

	

	var level=document.order_form.academiclevel.value

	var month=document.order_form.month.value

	var day=document.order_form.day.value

	var year=document.order_form.year.value

	var hours=document.order_form.hours.value

	var minutes=document.order_form.minutes.value



	if(level=="empty"){

		document.getElementById("rate_quote").innerHTML=""

	}

	if(level=="secondaryschool"){

		document.getElementById("rate_quote").innerHTML="from $11.95 per page"

	}

	if(level=="highschool"){

		document.getElementById("rate_quote").innerHTML="from $11.95 per page"

	}

		if(level=="2yearcollege"){

		document.getElementById("rate_quote").innerHTML="from $13.95 per page"

	}

	if(level=="4yearcollege"){

		document.getElementById("rate_quote").innerHTML="from $14.95 per page"

	}

	if(level=="graduate"){

		document.getElementById("rate_quote").innerHTML="from $16.95 per page"

	}

	if(level=="phd"){

		document.getElementById("rate_quote").innerHTML="from $19.95 per page"

	}

}

function word_count(){

	var type=document.order_form.type.value

	var pages=document.order_form.pages.value

		if (pages!=="empty" && type!=="empty" && type!=="powerpoint" && type!=="quantitative_project_accounting" && type!=="quantitative_project_finance" && type!=="quantitative_project_statistics")

		{

			document.getElementById("wordcount").style.fontSize="8pt"

			document.getElementById("wordcount").style.color="#666666"

			document.getElementById("wordcount").style.fontWeight="normal"

			document.getElementById("wordcount").innerHTML="Word Count: approx.&nbsp;"+pages*290+"&nbsp;words (290 words per page)<br>Format: 12 pt Times New Roman font, double spacing, 1 inch margins"

		}

		else{

			document.getElementById("wordcount").innerHTML=""

		}

}

function change_backgroundmenu(td)

{

	td.style.backgroundColor="#d6f1ad"

	td.previousSibling.previousSibling.style.background="url(http://www.customessaymeister.com/images/menumaincorneract.gif) bottom right no-repeat"

	td.previousSibling.style.background="#d6f1ad url(http://www.customessaymeister.com/images/menumainact.gif) top right no-repeat"

	td.nextSibling.style.background="#d6f1ad url(http://www.customessaymeister.com/images/menumainactr.gif) top left no-repeat"

	td.nextSibling.nextSibling.style.background="url(http://www.customessaymeister.com/images/menumaincorneractr.gif) bottom left no-repeat"

}

function return_backgroundmenu(td)

{

	td.style.backgroundColor="#b6e76d"

	td.previousSibling.previousSibling.style.background="url(http://www.customessaymeister.com/images/menumaincornerpas.gif) bottom right no-repeat"

	td.previousSibling.style.background="#b6e76d url(http://www.customessaymeister.com/images/menumainpas.gif) top right no-repeat"

	td.nextSibling.style.background="#b6e76d url(http://www.customessaymeister.com/images/menumainpasr.gif) top left no-repeat"

	td.nextSibling.nextSibling.style.background="url(http://www.customessaymeister.com/images/menumaincornerpasr.gif) bottom left no-repeat"

}

function change_backgroundmenu_sec(td,color)

{

	td.previousSibling.firstChild.src="http://www.customessaymeister.com/images/tc1_act.gif"

	td.nextSibling.firstChild.src="http://www.customessaymeister.com/images/tc2_act.gif"

	td.style.background="url(http://www.customessaymeister.com/images/tc_bg_act.gif)"

	td.firstChild.style.color="#ffffff"

}

function return_backgroundmenu_sec(td,color)

{

	td.previousSibling.firstChild.src="http://www.customessaymeister.com/images/tc1.gif"

	td.nextSibling.firstChild.src="http://www.customessaymeister.com/images/tc2.gif"

	td.style.background="url(http://www.customessaymeister.com/images/tc_bg.gif)"

	td.firstChild.style.color="#666666"



}



function change_background(field,color)

{

	field.style.backgroundColor=color

}

function showfaq(id)

{

	if(document.getElementById(id).style.display=='none')

	{

		document.getElementById(id).style.display='block'


	}

	else

	{	

		document.getElementById(id).style.display='none'


	}

}

function showcategory(id)

{

	if(document.getElementById(id).style.display=='none')

	{

		document.getElementById(id).style.display='block'

		document.getElementById(id+"_img").src="http://www.customessaymeister.com/images/arrow_category_close.gif"

	}

	else

	{	

		document.getElementById(id).style.display='none'

		document.getElementById(id+"_img").src="http://www.customessaymeister.com/images/arrow_category_open.gif"

	}

}



function ga(o,e)

	{

	var a,f,g,h,p,r,t; 

	if (document.getElementById)

	{

		a="u"+o.id; 

		p = "";

		r = "";

		g = e.target;

		if (g) { 

			t = g.id;

			f = g.parentNode;

			if (f) {

			p = f.id;h = f.parentNode;

				if (h) r = h.id;

			}

	} 

		else{

			h = e.srcElement;

			f = h.parentNode;

			if (f) p = f.id;

			t = h.id;}

			if (t==a || p==a || r==a) return true;

			location.href=document.getElementById(a).href

		}

}

function td_url(o,url)

{	

		location.href=url

}



//AJAX RELATED

function makeRequest(action,url,essaysample_id,td) {

       

	   var passData="action="+action+"&essaysample_id="+essaysample_id;

	   

	   var http_request = false;



        if (window.XMLHttpRequest) { // Mozilla, Safari, ...

            http_request = new XMLHttpRequest();

            if (http_request.overrideMimeType) {

                http_request.overrideMimeType('text/xml');

            }

        } else if (window.ActiveXObject) { // IE

            try {

                http_request = new ActiveXObject("Msxml2.XMLHTTP");

            } catch (e) {

                try {

                    http_request = new ActiveXObject("Microsoft.XMLHTTP");

                } catch (e) {}

            }

        }



        if (!http_request) {

            alert('Error: Unable to initialize class');

            return false;

        }

        http_request.onreadystatechange = function() { alertContents(http_request,action,essaysample_id,td); };

        http_request.open('POST', url, true);

       	http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');  

		http_request.send(passData);



    }



function alertContents(http_request,action,essaysample_id,td) {



        if (http_request.readyState == 4) {

            if (http_request.status == 200) {

			   

			   if(!td.disable){

					td.disable=true;

					var ctrl=document.getElementById(essaysample_id);

				   

				   if(action=='votes_up'){

					   ctrl.childNodes[0].childNodes[0].innerHTML++;

					   ctrl.childNodes[0].childNodes[0].className='voteuppas';

					   ctrl.childNodes[0].childNodes[1].className='votedownpas';

					   ctrl.removeChild(ctrl.childNodes[1])

					}

				   else if(action=='votes_down'){

					   ctrl.childNodes[0].childNodes[1].innerHTML++;

					   ctrl.childNodes[0].childNodes[0].className='voteuppas';

					   ctrl.childNodes[0].childNodes[1].className='votedownpas';

					   ctrl.removeChild(ctrl.childNodes[1])

					}

				}

			

            } else {

                alert('Request has failed');

            }

        }



    }


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var email=document.order_form.email
	var email2=document.order_form.email2

	if ((email.value==null)||(email.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(email.value)==false){
		email.value=""
		email.focus()
		return false
	}
	if (echeck(email2.value)==false){
		email2.value=""
		email2.focus()
		return false
	}

	return true
 }

function fetch_client_data(url){
	var login=document.getElementById('client_login').value;
	var password=document.getElementById('client_password').value;
   	
	var passData="login="+login+"&password="+password;
	var http_request = false;
	
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
	    http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
	        http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) {
        alert('Error: Unable to initialize class');
        return false;
    }

	http_request.onreadystatechange = function() { fetchContents(http_request); };
    http_request.open('POST', url, true);
  	http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');  
	http_request.send(passData);
}



function fetchContents(http_request) {
	if (http_request.readyState == 4) {
        if (http_request.status == 200) {
			if(http_request.responseText=='false'){
			   document.getElementById('fetch_client_message').innerHTML="Incorrect login or password";
			}
			else{
				var text=http_request.responseText;
				text=text.split("|");
				document.getElementById('firstname').value=text[0];
				document.getElementById('lastname').value=text[1];
				document.getElementById('email').value=text[2];
				document.getElementById('email2').value=text[3];
				document.getElementById('phone').value=text[4];
				document.getElementById('address').value=text[5];
				document.getElementById('city').value=text[6];
				document.getElementById('state').value=text[7];
				document.getElementById('zip').value=text[8];
				document.getElementById('country').value=text[9];

				document.getElementById('fetch_client_message').innerHTML="Welcome "+text[0];
			}
		} 
		else {
		    alert('Request has failed');
		}
    }
}

function checkformextrapages(obj){
	var pages=document.formextrapages.pages.value;
	var paymethod=document.formextrapages.payment_method.value
	if(pages=='empty' || paymethod=='empty'){
		alert('Please select the number of pages and checkout method');	
	}
	else{
		document.formextrapages.submit();	
	}
}

function fetch_forex(url,cur_from,cur_to){
	//var amount=document.getElementById('dynaquote').innerHTML;
	var amount=document.getElementById('dynaquote').innerHTML;
	if(cur_to!='empty'){
		document.getElementById('forex').innerHTML='<img src=\'https://www.customessaymeister.com/images/loading.gif\'>';
	}
	var passData="amount="+amount+"&cur_from="+cur_from+"&cur_to="+cur_to;
	var http_request = false;
	
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
	    http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
	        http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) {
        alert('Error: Unable to initialize class');
        return false;
    }

	http_request.onreadystatechange = function() { alert_forex(http_request,cur_to); };
    http_request.open('POST', url, true);
  	http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');  
	http_request.send(passData);
}



function alert_forex(http_request,cur_to) {
	if (http_request.readyState == 4) {
        if (http_request.status == 200) {
			if(cur_to!='empty'){
				//alert(http_request.responseText);
				document.getElementById('forex').innerHTML='&nbsp;=&nbsp;'+http_request.responseText;
			}
		} 
		else {
		    alert('Request has failed');
		}
    }
}

function country_cc(url,country){
	document.getElementById('country_cc').innerHTML='<img src=\'https://www.customessaymeister.com/images/loading.gif\'>';
	var passData="country="+country;
	var http_request = false;
	
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
	    http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
	        http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) {
        alert('Error: Unable to initialize class');
        return false;
    }

	http_request.onreadystatechange = function() { alert_country_cc(http_request); };
    http_request.open('POST', url, true);
  	http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');  
	http_request.send(passData);
}



function alert_country_cc(http_request) {
	if (http_request.readyState == 4) {
        if (http_request.status == 200) {
			//alert(http_request.responseText);
			document.getElementById('country_cc').innerHTML=http_request.responseText;
		} 
		else {
		    alert('Request has failed');
		}
    }
}
function quote(url) {
	var type=document.order_form.type.value;
	var level=document.order_form.academiclevel.value;
		
	var day=document.order_form.day.value;
	var month=document.order_form.month.value;
	var year=document.order_form.year.value;
	var hours=document.order_form.hours.value;
	var minutes=document.order_form.minutes.value;
	var noon=document.order_form.noon.value;

	if(type=="quantitative_project_accounting" || type=="quantitative_project_finance" || type=="quantitative_project_statistics"){
		document.getElementById('pagestitle').innerHTML='Number of problems/questions';
	}
	else if(type=="powerpoint"){
		document.getElementById('pagestitle').innerHTML='Number of slides';
	}
	else{
		document.getElementById('pagestitle').innerHTML='Number of pages';
	}
		
	var pages=document.order_form.pages.value;
	if(type!=="empty" && level!=="empty" && pages!=="empty"){
		document.getElementById('dynaquoteproc').innerHTML='<img src=\'https://www.customessaymeister.com/images/ajax-loader.gif\'>';
		document.getElementById('dynaquotetab').style.display='none';
	}
	var datasend="type="+type+"&level="+level+"&day="+day+"&month="+month+"&year="+year+"&hours="+hours+"&minutes="+minutes+"&noon="+noon+"&pages="+pages;
	var http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    	http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
               http_request.overrideMimeType('text/xml');
            }
       } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Error: Unable to initialize class');
            return false;
        }
        http_request.onreadystatechange = function() { quoteback(http_request,type,pages); };
        http_request.open('POST', url, true);
       	http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');  
		http_request.send(datasend);
}

function quoteback(http_request,type,pages) {
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
				document.getElementById('dynaquoteproc').innerHTML='';
				if(http_request.responseText!='failed' && http_request.responseText!='3'){
					var array=http_request.responseText.split("|");
				  	
					var rate = array[0];
				  	var total = array[1];
				  	var timespan = array[2];
					var wcmin = array[3];
					var wcmax = array[4];

					document.getElementById('dynaquotetab').style.display='block';
					
					if(type=="quantitative_project_accounting" || type=="quantitative_project_finance" || type=="quantitative_project_statistics"){
						document.getElementById('dynaquotewordcount').innerHTML='<small>Project length:&nbsp;</small>'+pages+' problems/questions';
						document.getElementById('dynaquoterate').innerHTML='<small>Rate per problem:&nbsp;</small>$'+rate;
					}
					else if(type=="powerpoint"){
						document.getElementById('dynaquotewordcount').innerHTML='<small>Project length:&nbsp;</small>'+pages+' slides';
						document.getElementById('dynaquoterate').innerHTML='<small>Rate per slide:&nbsp;</small>$'+rate;
					}
					else{
						document.getElementById('dynaquotewordcount').innerHTML='<small>Total wordcount:&nbsp;</small>'+wcmin+' - '+wcmax+' words';
						document.getElementById('dynaquoterate').innerHTML='<small>Rate per page:&nbsp;</small>$'+rate;
					}

					document.getElementById('dynaquote').innerHTML=total;
					document.getElementById('dynaquotetime').innerHTML='<small>Time span:&nbsp;</small>'+timespan;

					
					
					document.getElementById('forex').innerHTML='';
					document.order_form.forexname.value='empty'
				}
				if(http_request.responseText=='3'){
					alert('Error: Wrong deadline! Our minimum turnaround is 3 hours and it is applicable to short and relatively easy projects that are less than 5 pages in length. Please edit the deadline accordingly.');
					document.getElementById('dynaquotetab').style.display='none';
				}

			} else {
                alert('Request has failed');
            }
        }
    }