var contactState = -300;
function showContact() {
	if(contactState < 11) {
		v = document.getElementById('contactF');
		v.style.left = (contactState) + 'px';
		contactState += 10;
		t = setTimeout("showContact();",0);
	}
}

function hideContact() {
	if(contactState > -311) {
		v = document.getElementById('contactF');
		v.style.left = (contactState) + 'px';
		contactState -= 10;
		t = setTimeout("hideContact();",0);
	}
}

var st = 0;
var t;
var wi = 0;
var he = 0;
igrec = 230;

function promo() {
	switch(st) {
		//initialy
		case 0: {
			v = document.getElementById('promo');
			st = 1;
			if(wi < 400) {
				wi += 8;
				v.style.width = (wi) + 'px';
				st = 0;
			}
			if(he < 230) {
				he += 4;
				v.style.height = (he) + 'px';
				st = 0
			}
			if(igrec > 0) {
				igrec -= 4;
				v.style.top = (igrec) + 'px';
				st = 0;
			}
			if(st == 0) {
				v.innerHTML = '<div class="closeB" onclick="changestate(2);promo();"><img src="http://www.flash-template-design.com/images/minimize.png" alt="minimize"/></div><div class="promoContent"><img src="images/test1.png" alt="Promo code"/></div><div class="promoText"><p>Easter brings you a 25% off the price of any template.</p><br/><p>Use the <b>EASTER</b> coupon code when purchasing any template and get a 25% discount</p></div>';
			}
			t = setTimeout("promo();",0);
		} break;
		case 2: {
			v = document.getElementById('promo');
			st = 1;
			if(wi > 70) {
				wi -= 8;
				v.style.width = (wi) + 'px';
				st = 2;
			}
			if(he > 110) {
				he -= 4;
				v.style.height = (he) + 'px';
				st = 2
			}
			if(igrec < 230) {
				igrec += 4;
				v.style.top = (igrec) + 'px';
				st = 2;
			}
			if(st == 1) {
				v.innerHTML = '<div class="promoContent2" onclick="changestate(0);promo();mouseou();"><img src="http://www.flash-template-design.com/images/smalltest1.png" alt="Promo code" onmouseover="mouseov()" onmouseout="mouseou()"/></div>';
			}
			t = setTimeout("promo();",0);
		} break;
		default: break;
	}
}

function changestate(x) {
	st = x;	
}

function mouseov() {
	document.body.style.cursor = "pointer";
}

function mouseou() {
	document.body.style.cursor = "auto";
}

// Only script specific to this form goes here.
// General-purpose routines are in a separate file.
function validateOnSubmit() {
	var elem;
	var errs=0;
	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.
	if (!validatePresent(document.forms.form1.description, 'inf_from')) errs += 1;
	if (!validatePresent(document.forms.form1.name, 'inf_name')) errs += 1;
	if (!validateEmail(document.forms.form1.email, 'inf_email', true)) errs += 1;
	if (!validatePresent(document.forms.form1.captcha, 'inf_captcha', true)) errs += 1;
	
	if (errs>1) alert('There are fields which need correction before sending');
	if (errs==1) alert('There is a field which needs correction before sending');
	
	if(errs == 0) {
		var name=document.forms['form1'].elements['name'].value;
		var email=document.forms['form1'].elements['email'].value;
		var domain=document.forms['form1'].elements['domain'].value;
		var captcha=document.forms['form1'].elements['captcha'].value;
		var url=document.location.href;
	    var description=document.forms['form1'].elements['description'].value;
		var x = 'name='+name+'&email='+email+'&domain='+domain+'&url='+url+'&description='+description+'&captcha='+captcha;
		sendPostRequest(x);
		deactivateSubmit();
	}
}
 
function sendPostRequest(x) {
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
		  document.getElementById('messageSent').innerHTML = xmlhttp.responseText;
		   document.getElementById('messageSent').style.color = "#fff";
		   document.getElementById('messageSent').style.textDecoration = "blink";
		   document.getElementById('messageSent').style.textAlign = "center";
		   if(xmlhttp.responseText.substr(0, 5) == 'Wrong') {
			   document.getElementById('messageSent').style.backgroundColor = "#f00";
			   document.getElementById('pSent').style.backgroundColor = "#f00";
			   document.getElementById('vimg2').src = 'http://www.flash-template-design.com/validate_img.php?' + (new Date()).getTime();
			   alert ('The verification code was wrong, your request was not sent!');
		   }
		   else 
		   {
			   	document.getElementById('messageSent').style.color = "#346908";
				document.getElementById('messageSent').style.backgroundColor = "#cbec74";
				document.getElementById('pSent').style.backgroundColor = "#cbec74";
				document.getElementById('vimg2').src = 'http://www.flash-template-design.com/validate_img.php?' + (new Date()).getTime();
				document.getElementById('requiredFields').innerHTML = 'Your request has been sent!';
				document.getElementById('requiredFields').style.paddingLeft = '80px';
				deactivateSubmit();
				t = setTimeout("hideContact();",5000);
		   }
	  }
	  }
	  
	  var url = "http://www.flash-template-design.com/submit_new_custom.php";
	  var params = x;
	  xmlhttp.open("POST", url, true);

	  //Send the proper header information along with the request
	  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	  xmlhttp.setRequestHeader("Content-length", params.length);
	  xmlhttp.setRequestHeader("Connection", "close");
	  
	  xmlhttp.send(params);
}

function deactivateSubmit() {
	document.forms['form1'].elements['Submit'].setAttribute('disabled', 'true');
	timeoutt = setTimeout("activateSubmit();",20000);
}

function activateSubmit() {
	document.forms['form1'].elements['Submit'].removeAttribute("disabled");
}

function showhiderefund() {
	x = document.getElementById('refund').style.display;
	if(x=="none") 
		document.getElementById('refund').style.display = "block";
	else 
		document.getElementById('refund').style.display = "none";	
}
