function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function pricesObj(id, p,up){
 this.ID = id;
 this.price=p;
 this.uniquePrice=up;
 this.selectedPrice=0;
 //0 for price;
 //1 for unique price;
}
function setSelectedPrice(id, selP){
	array_prices[id].selectedPrice=selP;
	var i=0;
	var sum=0;
	var items=""
	for(i=0;i<array_prices.length;i++)
	{
		items+=array_prices[i].ID + "," + array_prices[i].selectedPrice;
		if(i<array_prices.length-1)
			items+=";";
		if(array_prices[i].selectedPrice==0)
			sum+=array_prices[i].price;
		else
			sum+=array_prices[i].uniquePrice;
	}
	pa=document.getElementById('paymentAmount');
	pa.innerHTML="<strong> "+sum+"&#8364</strong>";
	document.paymentFormPayPal.amount.value=sum;
	document.paymentFormPayPal.custom.value=items;
	document.paymentFormMoneyBookers.amount.value=sum;
	document.paymentFormMoneyBookers.custom_field.value=items;
	
}
function checkOut()
{
	var pmMB=document.getElementById('chkbPaymentMethodMB');
	var pmPP=document.getElementById('chkbPaymentMethodPP');
	var agreement=document.getElementById('licenceAgree');
	if(!pmMB.checked && !pmPP.checked)
	{
		alert('Please select a payment method!');
		return;
	}
	if(!agreement.checked)
	{
		alert('You need to accept the Terms of Use to place an order!');
		return;
	}
	if(pmPP.checked) document.paymentFormPayPal.submit();
	if(pmMB.checked) document.paymentFormMoneyBookers.submit();
	
}

   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!")
		   return false
		}

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

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

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

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

 		 return true					
	}


function submitForm(){
	var emailID=document.mainForm.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
 
 function submitCustomWork(){

	 if(document.formCW.fullName.value.length<3)
	 {
		 alert('Plese input your name!');
		 document.formCW.fullName.focus();
		 return false;
	 }
	 
	 var emailID=document.formCW.email;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	 
	 if(document.formCW.company.value.length<3)
	 {
		 alert('Plese input your company\'s name!');
		 document.formCW.company.focus();
		 return false;
	 }
	 
	 
	 if(document.formCW.description.value.length<10)
	 {
		 alert('Plese give a short description of your project!');
		 document.formCW.description.focus();
		 return false;
	 }

	
	return true
 }
 
function wishListSubmit()
{
if(document.wishlistForm.wish.value.length<10){
	alert('Please make a wish and then submit it!');
	document.wishlistForm.wish.focus();
	return;
}
var xmlHttp;
var msg="0 The request is not initialized\n1 The request has been set up\n2 The request has been sent\n3 The request is in process\n4 The request is complete\n";
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      	 myDiv=document.getElementById('wishListDivContent');
		 myDiv.innerHTML=xmlHttp.responseText;
      }
	  else if(xmlHttp.readyState==1){
		  myDiv=document.getElementById('wishListDivContent');
		  myDiv.innerHTML="sending the wish ...";
	  }
	  /*else
	  	 myDiv=document.getElementById('wishListDivContent');
		 myDiv.innerHTML=xmlHttp.readyState;*/
    }
  xmlHttp.open("POST","AJAX/wishList.php",true);
  var poststr = 'wish='+document.wishlistForm.wish.value;
  xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xmlHttp.send(poststr);
}
