// JScript File

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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) var a;//alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function chk(strFields)
{
    var e=document.getElementById("chkTermsAgreement");
    if(e.checked)
    {
        if(strFields!=""){
            if(dispAlert(strFields)){
                return true;
            }else{
                return false;
            }
        }else{
            return true;
        }
    }
    else
    {
        alert("You must agree to terms to continue");
        return false;
    }
}

function deactivateState()
{
    var x=document.getElementById('drpCountry');
    if(x.options[x.selectedIndex].text=='United States')
        document.getElementById('drpState').disabled=false;
    else
        {
            document.getElementById('drpState').disabled=true;
            //document.getElementById('drpState').selectedIndex=-1;
        }
}
function checkCharacters(strVal){
	j_maj = strVal.length;
	validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.+,<>#;?- @1234567890"\'&!=_-:/';
	for(i_maj=0; i_maj<j_maj; i_maj++){
		if (validChars.indexOf(strVal.charAt(i_maj))<0){
			i_maj=99;
			return true;
		}
	}	
	return false;	
}

function YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
  var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
  for (i=1; i<a.length;i=i+4){
    if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
    o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
    o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
    v=o.value;t=a[i+2];
    validChar=false;
    if (o.type=='text'||o.type=='password'||o.type=='hidden'){
      if (r&&v.length==0){err=true}
	  if(checkCharacters(v)){
		  err=true;	
		  validChar=true;
	  }
      if (v.length>0)
      if (t==1){ //fromto
        ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
      } else if (t==2){
        rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
      } else if (t==3){ // date
        ma=a[i+1].split("#");at=v.match(ma[0]);
        if(at){
          cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
          dte=new Date(cy,cm,cd);
          if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
        }else{err=true}
      } else if (t==4){ // time
        ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
      } else if (t==5){ // check this 2
            if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!o1.checked){err=true}
      } else if (t==6){ // the same
            if(v!=MM_findObj(a[i+1]).value){err=true}
      } else if(t==7){ // Execute function with object's value as a parameter
	  	var arrFunc = a[i+1].split('#');
		if(arrFunc[1]!=""){
			eval("var resDynamicCall = "+arrFunc[1]+"('"+v+"')");
			if(resDynamicCall){	}else{ err=true;}
		}
	  }
    } 
	else if (!o.type&&o.length>0&&o[0].type=='radio'){
          at = a[i].match(/(.*)\[(\d+)\].*/i);
          o2=(o.length>1)?o[at[2]]:o;
      if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
      if (t==2){
        oo=false;
        for(j=0;j<o.length;j++){oo=oo||o[j].checked}
        if(!oo){s+='* '+a[i+3]+'\n'}
      }
    } 
	else if (o.type=='checkbox'){
      if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
    } 
	else if (o.type=='select-one'||o.type=='select-multiple'){
      if(t==1&&o.selectedIndex/1==0){err=true}
    }
	else if (o.type=='textarea'){
      if(v.length<a[i+1]){err=true}
    }
    if (err){
		extra_s = '';
		if(validChar) extra_s=' '+'Must be Valid Characters...';
		s+='* '+a[i+3]+extra_s+'\n'; 
		err=false;
	}
  }
  if (s!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+s)}
  document.MM_returnValue = (s=='');
}
/*
function toggle(objnm)
{
	//alert(document.getElementById(objnm).style.display);
	if(document.getElementById(objnm).style.display	=='none')
	{
		document.getElementById(objnm).style.display='block';
		//document.getElementById("btn"+objnm).value='«';
	}
	else
	{
		document.getElementById(objnm).style.display='none';
		//document.getElementById("btn"+objnm).value='»';
	}
}

function validateZIP(field) 
{
    var valid = "0123456789-";
    var hyphencount = 0;

    if (field.length!=5 && field.length!=10) 
    {
        //alert("Please enter your 5 digit or 5 digit+4 zip code.");
        return false;
    }
    for (var i=0; i < field.length; i++) 
    {
        temp = "" + field.substring(i, i+1);
        if (temp == "-") hyphencount++;
        if (valid.indexOf(temp) == "-1") 
        {
            //alert("Invalid characters in your zip code.  Please try again.");
            return false;
        }
        if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) 
        {
            //alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
            return false;
        }
    }
return true;
}

function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function checkNumber(val)
{
  var strPass = val.value;
  var strLength = strPass.length;
  for(i=0;i<strLength;i++)
  {
      var lchar = val.value.charAt(i);
      var cCode = CalcKeyCode(lchar);
      if (cCode < 48 || cCode > 57 )
      {
        return false;
      }
  }
  return true;
}

// returns true if the string is a US phone number formatted as...
// (000)000-0000, (000) 000-0000, 000-000-0000, 000.000.0000, 000 000 0000, 0000000000
function isPhoneNumber(str)
{
  var re = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/
  return re.test(str);
}


function checkBox(subjects)
{
    var Sub=subjects.split(',');
    var chkNo;
    for(i=0;i<Sub.length;i++)
    {
        if(Sub[i]!="")
        {
            if(Sub[i]>25)
            {
                Sub[i]=Sub[i]-26;
                chkNo=2;
            }
            else
            {
                Sub[i]=Sub[i]-1;
                chkNo=1;
            }
            //alert('chkSubjects'+chkNo+'_'+Sub[i]);
            document.getElementById('chkSubjects'+chkNo+'_'+Sub[i]).checked=true;
        }
    }
}

function checkDate(){
    var rdObj;
    rdObj = document.getElementById("chkUnpublish");
    dateObj = document.getElementById("txtPublicationDate");
    btnObj = document.getElementById("btnContinue");
    if(rdObj.checked){
        dateObj.value="";
        btnObj.onclick = function() {
            return dispAlert('txtPublisherName,txtStreet1,txtCity,txtZipCode,txtTelephone,txtFax,txtEmail,txtCoordinatorName,txtCoordinatorTitle,txtCoordinatorTelephone,txtRightsCntTelephone,txtStrtYearPublishing,txtTitle,txtCopyrightYear,txtNoOfPages,txtBookSize,txtLanguage,txtRetailPrice,txtAge,txtContributor,txtContributorTitle');
        }
    }else{
        btnObj.onclick = function() {
            return dispAlert('txtPublisherName,txtStreet1,txtCity,txtZipCode,txtTelephone,txtFax,txtEmail,txtCoordinatorName,txtCoordinatorTitle,txtCoordinatorTelephone,txtRightsCntTelephone,txtStrtYearPublishing,txtTitle,txtPublicationDate,txtCopyrightYear,txtNoOfPages,txtBookSize,txtLanguage,txtRetailPrice,txtAge,txtContributor,txtContributorTitle');
        }
    }
}

function move(fbox, tbox) {
     var arrFbox = new Array();
     var arrTbox = new Array();
     var arrLookup = new Array();
     var i;
     for(i=0; i<tbox.options.length; i++) {
          arrLookup[tbox.options[i].text] = tbox.options[i].value;
          arrTbox[i] = tbox.options[i].text;
     }
     var fLength = 0;
     var tLength = arrTbox.length
     for(i=0; i<fbox.options.length; i++) {
          arrLookup[fbox.options[i].text] = fbox.options[i].value;
          if(fbox.options[i].selected && fbox.options[i].value != "") {
               arrTbox[tLength] = fbox.options[i].text;
               tLength++;
          } else {
               arrFbox[fLength] = fbox.options[i].text;
               fLength++;
          }
     }
     arrFbox.sort();
     arrTbox.sort();
     fbox.length = 0;
     tbox.length = 0;
     var c;
     for(c=0; c<arrFbox.length; c++) {
          var no = new Option();
          no.value = arrLookup[arrFbox[c]];
          no.text = arrFbox[c];
          fbox[c] = no;
     }
     for(c=0; c<arrTbox.length; c++) {
     	var no = new Option();
     	no.value = arrLookup[arrTbox[c]];
     	no.text = arrTbox[c];
     	tbox[c] = no;
     }
}

function selectAll(box) {
     for(var i=0; i<box.length; i++) {
     	box[i].selected = true;
     }
}               

function setClientData(strCustomerID){
	FireBasicAjaxRequest('type=getDetail&customerID='+strCustomerID, 'admin/customer.php','div_status');
	return false;
}

function check4UploadField(val){
	//alert(val);
	try{
		if((val!="") && (!isNaN(val)) && (val>0)){
			document.getElementById("tr_upload").style.display = "";	
		}else{
			document.getElementById("tr_upload").style.display = "none";		
		}
	}catch(ex){
	}
}
function checkSendAssignment(cntChk){
	var arrChecked = Array();
	cntArr = 0;
	for(c=1;c<=cntChk;c++){
		var chkStatus = document.getElementById('chk_'+c);
		if (chkStatus.checked){
			arrChecked[cntArr] = chkStatus.value;
			cntArr++;
		}
	}
	strChecked = arrChecked.join(",");
	if (strChecked!=""){
		FireAjaxRequest('type=sendAssignment&isbnID='+strChecked, 'admin/isbn_assignment.php','div_list','div_status','block');
	}else{
		alert("Please select ISBN to send...");
		return false;
	}
	
}
function checkISBNValidation(strISBN){
	strISBN = strISBN.replace(/-/g,'');
	if (strISBN.length==13){
		var arr = strISBN.match(/\d{13}/);
		if (arr.length>0){
			sum12 = 0;
			for (i=0;i<strISBN.length-1;i++){
				var charInd = strISBN.charAt(i);
				if ((i%2)==0){
					sum12 = parseInt(sum12) + (parseInt(charInd)*1);
				}else{
					sum12 = parseInt(sum12) + (parseInt(charInd)*3);	
				}
			}
			//alert(sum12);
			checkSum = 10 - (parseInt(sum12) %10);
			if(parseInt(checkSum)==10) checkSum = 0;
			if(checkSum==parseInt(strISBN.charAt(strISBN.length-1))){
				return true;
			}else{
				return false;
			}
		}else{
			return false;
		}
	}else{
		return false;
	}
}*/

function addLoadEvent(func) { 
  //alert("add");
  var oldonload = window.onload; 
  if (typeof window.onload != 'function') { 
    window.onload = func; 
  } else { 
    window.onload = function() { 
      if (oldonload) { 
        oldonload(); 
      } 
      func(); 
    } 
  } 
} 
/*
function showPrint(){
	arr = document.getElementsByName("chkOrder");
	chkID = Array();
	for(i=0;i<arr.length;i++){
		if(arr[i].checked){
			chkID[chkID.length]=arr[i].value;
		}
	}
	if((chkID.length==1) && (document.getElementById("certificate_id").value!="")){
		window.open("printOrder.php?id="+chkID.join(",")+"&certificate_id="+document.getElementById("certificate_id").value,"PrintOrder","scrollbars=yes,status=no,menubar=no,height=600,width=700");
	}else{
		alert("Please Select only 1 order & Certificate to print");
		return false;
	}
	/*if(chkID.length>3){
		alert("Please select upto 3 orders to fit in single page");
	}else{
		if((chkID.length>=1) && (chkID.length<=3)){
			window.open("printOrder.php?id="+chkID.join(","),"PrintOrder","scrollbars=yes,status=no,menubar=no,height=600,width=700");
		}else{
			alert("Please select atleas 1 order to Print...");
		}
	}* /	
}
function findPosX(obj)
{
    var curleft = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function saveXY(){
	document.getElementById("hidden_div_1").value = findPosX(document.getElementById("div_1"))+","+findPosY(document.getElementById("div_1"));
	document.getElementById("hidden_div_2").value = findPosX(document.getElementById("div_2"))+","+findPosY(document.getElementById("div_2"));
	document.getElementById("hidden_div_3").value = findPosX(document.getElementById("div_3"))+","+findPosY(document.getElementById("div_3"));
	//alert(document.getElementById("hidden_div_1").value);
	//alert(document.getElementById("hidden_div_2").value);
	//alert(document.getElementById("hidden_div_3").value);
	return true;
}
*/
function addtoCart(serID){
	//alert(serID);
	FireAjaxRequest("action=add&id="+serID, "myCart.php","divMyCart","divStatus","block");
}
function removefromCart(serID){
	//alert(serID);
	FireAjaxRequest("action=remove&id="+serID, "myCart.php","divMyCart","divStatus","block");
}
function displayCapper(capperID){
	divName = "capper_"+capperID;
	document.write("<div id='"+divName+"'></div>");
	document.write("<div id='"+divName+"_status'></div>");		
	FireAjaxRequest("capperID="+capperID,"capperRandom.php",divName,divName+"_status","block");
}

function displayAllAccess(accessPassID){
	divName = "div_AllAccess"+accessPassID;
	document.write("<div id='"+divName+"'></div>");
	document.write("<div id='"+divName+"_status'></div>");		
	FireAjaxRequest("all_access_id="+accessPassID,"capperRandom.php",divName,divName+"_status","block");
}

function displayToutBox(capperID){
	divName = "div_TB"+capperID;
	document.write("<div id='"+divName+"'></div>");
	document.write("<div id='"+divName+"_status'></div>");		
	FireAjaxRequest("tout_capper_id="+capperID,"capperRandom.php",divName,divName+"_status","block");
}

function displayAnyCapper(accessPassID){
	divName = "div_AnyCapper"+accessPassID;
	document.write("<div id='"+divName+"'></div>");
	document.write("<div id='"+divName+"_status'></div>");		
	FireAjaxRequest("all_access_id="+accessPassID,"capperRandom.php",divName,divName+"_status","block");
}

function getRecords(strType,member_id,capper_id){
	if(strType==""){
		buttonGroup[0].checked = true;
		strType = "S";
	}
	FireAjaxRequest("type=manage_service_pre&capperID="+capper_id+"&member_id="+member_id+"&displayType="+strType,"admin/member.php","div_my_ser_add","div_my_ser_status","block");
}

function getSelectedRadio(bG) {
   buttonGroup = document.getElementsByName(bG); 
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(bG) {
	buttonGroup = document.getElementsByName(bG); 
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(bG);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function




function displayRandomCapper(){
	document.write("<div id='randomCapper'></div>");	
	ajaxFunction("capperRandom.php?rnd="+Math.random(),"randomCapper");
}

function displayPodcast(podID){
	document.write("<div id='pod"+podID+"'></div>");	
	ajaxFunction("podDisplay.php?podID="+podID+"&rnd="+Math.random(),"pod"+podID+"");
}

function displayPick(pickID){
	document.write("<div id='pick"+pickID+"'></div>");	
	ajaxFunction("pickDisplay.php?pickid="+pickID+"&rnd="+Math.random(),"pick"+pickID+"");
}

function displayMyPick(pickID){	
	document.write("<div id='myPick"+pickID+"'></div>");	
	ajaxFunction("pickDisplay.php?pickid="+pickID+"&rnd="+Math.random(),"myPick"+pickID+"");
}

function displayOneGame(oneGameID){
	document.write("<div id='myOneGame"+oneGameID+"'></div>");	
	ajaxFunction("oneGameDisplay.php?oneGameID="+oneGameID+"&rnd="+Math.random(),"myOneGame"+oneGameID+"");
}
