function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  var smallwin = window.open(theURL,winName,features);
  smallwin.focus();
}


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 setCurrency(theChoice){

var cookieValue = theChoice.options[theChoice.selectedIndex].value
var expDate = new Date();
var cookieName = "currencychoice"
var expiry = 1000 * 60 * 60 * 24 * 365

if( expiry >  0 ) 	{
		expDate.setTime(expDate.getTime() + expiry);
//		alert(" about to write cookie " + cookieValue + " and expires " + expDate.toGMTString() );
		document.cookie = cookieName + "=" + escape (cookieValue) + "; expires=" + expDate.toGMTString();
}
else {
		document.cookie = cookieName + "=" + escape (cookieValue);
		}
}
	

function CookieDef(expires,path,domain,secure)
{
  this.secure = secure;
  this.path = path;
  this.domain = domain;
  this.getValue = getCookie;
  this.setValue = setCookie;
  this.expire = deleteCookie;
  if (expires == 0) {
    this.expires = "";
  } else {
    var today_date = new Date();
	 var expire_seconds = today_date.getTime() + (expires * 24 * 60 * 60  * 1000);
    today_date.setTime(expire_seconds);
    this.expires = today_date.toGMTString();
  }
}


function getCV(offset) {
  var endstr = document.cookie.indexOf(";", offset);
  if (endstr == -1) endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}


function getCookie(name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCV(j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return "";
}


function setCookie(name,value)
{
  document.cookie = name + "=" + escape(value) +
    ((this.expires == "") ? "" : ("; expires=" + this.expires)) +
    ((this.path == "") ? "" : ("; path=" + this.path)) +
    ((this.domain == "") ? "" : ("; domain=" + this.domain)) +
    ((this.secure == true) ? "; secure" : "");
}


function deleteCookie(name) {
  document.cookie = name + "=" + "" + "; expires=Thu,01-Jan-70 00:00:01 GMT";
}


function YY_checkform() { //v4.66
//copyright (c)1998,2002 Yaromat.com
  var args = YY_checkform.arguments; var myDot=true; var myV=''; var myErr='';var addErr=false;var myReq;
  for (var i=1; i<args.length;i=i+4){
    if (args[i+1].charAt(0)=='#'){myReq=true; args[i+1]=args[i+1].substring(1);}else{myReq=false}
    var myObj = MM_findObj(args[i].replace(/\[\d+\]/ig,""));
    myV=myObj.value;
    if (myObj.type=='text'||myObj.type=='password'||myObj.type=='hidden'){
      if (myReq&&myObj.value.length==0){addErr=true}
      if ((myV.length>0)&&(args[i+2]==1)){ //fromto
        var myMa=args[i+1].split('_');if(isNaN(myV)||myV<myMa[0]/1||myV > myMa[1]/1){addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==2)){
          var rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-z]{2,4}$");if(!rx.test(myV))addErr=true;
      } else if ((myV.length>0)&&(args[i+2]==3)){ // date
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);
        if(myAt){
          var myD=(myAt[myMa[1]])?myAt[myMa[1]]:1; var myM=myAt[myMa[2]]-1; var myY=myAt[myMa[3]];
          var myDate=new Date(myY,myM,myD);
          if(myDate.getFullYear()!=myY||myDate.getDate()!=myD||myDate.getMonth()!=myM){addErr=true};
        }else{addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==4)){ // time
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);if(!myAt){addErr=true}
      } else if (myV.length>0&&args[i+2]==5){ // check this 2
            var myObj1 = MM_findObj(args[i+1].replace(/\[\d+\]/ig,""));
            if(myObj1.length)myObj1=myObj1[args[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!myObj1.checked){addErr=true}
      } else if (myV.length>0&&args[i+2]==6){ // the same
            var myObj1 = MM_findObj(args[i+1]);
            if(myV!=myObj1.value){addErr=true}
      }
    } else
    if (!myObj.type&&myObj.length>0&&myObj[0].type=='radio'){
          var myTest = args[i].match(/(.*)\[(\d+)\].*/i);
          var myObj1=(myObj.length>1)?myObj[myTest[2]]:myObj;
      if (args[i+2]==1&&myObj1&&myObj1.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
      if (args[i+2]==2){
        var myDot=false;
        for(var j=0;j<myObj.length;j++){myDot=myDot||myObj[j].checked}
        if(!myDot){myErr+='* ' +args[i+3]+'\n'}
      }
    } else if (myObj.type=='checkbox'){
      if(args[i+2]==1&&myObj.checked==false){addErr=true}
      if(args[i+2]==2&&myObj.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
    } else if (myObj.type=='select-one'||myObj.type=='select-multiple'){
      if(args[i+2]==1&&myObj.selectedIndex/1==0){addErr=true}
    }else if (myObj.type=='textarea'){
      if(myV.length<args[i+1]){addErr=true}
    }
    if (addErr){myErr+='* '+args[i+3]+'\n'; addErr=false}
  }
  if (myErr!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+myErr)}
  document.MM_returnValue = (myErr=='');
}



function validateField(theField) {
	while ((theField.value.substring(0,1) == ' ') || (theField.value.substring(0,1) == '\n') || (theField.value.substring(0,1) == '\r')) {
		theField.value = theField.value.substring(1,theField.value.length);
	}

	if (theField.value == "")  {
		theField.value = 0 ;
	}
	
//	if isNaN(theField.value) == true {
//		window.alert("The Quantity field must contain a number " + theField.value);
//		theField.value=1 ;
//	}
	
}


function GetThumbSize(theForm,theImage) {
//	alert("about to set thumbnail size ") ;
//if (theForm.pictureThumbWidth.value == "")
	{
	theForm.pictureThumbWidth.value = theImage.width ;
	}

//if (theForm.pictureThumbHeight.value == "" )
	{
	theForm.pictureThumbHeight.value = theImage.height;
	}
}



function GetFullSize(theForm,theImage) {
	
//if (theForm.pictureFullWidth.value == "")
	{
	theForm.pictureFullWidth.value = theImage.width ;
	}

//if (theForm.pictureFullHeight.value == "" )
	{
	theForm.pictureFullHeight.value = theImage.height;
	}
}


function getProfit(theField) { 
 		if ( theField.name == "wsp")  {
			if (eval(window.document.updateForm.Price.value) > 0 ) { 
				window.document.updateForm.profit.value = eval(window.document.updateForm.Price.value) - eval(window.document.updateForm.wsp.value) ;
			}
		}

 		if ( theField.name == "Price")  {
			if (eval(window.document.updateForm.wsp.value) > 0 ) { 
				window.document.updateForm.profit.value = eval(window.document.updateForm.Price.value) - eval(window.document.updateForm.wsp.value) ;
			}
		}

 		if ( theField.name == "offerprice")  {
			if (eval(window.document.updateForm.wsp.value) > 0 ) { 
				window.document.updateForm.profit.value = eval(window.document.updateForm.offerprice.value) - eval(window.document.updateForm.wsp.value) ;
			}
		}

		
/*		else {
			if (theField.name == "Price") && (eval(window.document.updateForm.wsp.value) > 0 ) {
				window.alert("about to change profit based on Price ");
				window.document.updateForm.profit.value = eval(window.document.updateForm.Price.value) - eval(window.document.updateForm.wsp.value) ;
			}
		}
		*/
}




function populateFields() {
/*	var args , i , theField, theValue 
	args = populateFields.arguments ;
	
	
	for (i = 0 ; i < args.length ; i = i + 1 ) {
		if (theField = MM_findObj(args[i]) != null ) {
	
			
			if (args[i+1] != "") {
				theField.value = args[i+1] ; 
			}
	
	
		}
	}
*/
}
