/* Global JavaScript library for OCDLA.org */

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

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 DW_updateprice(x) { //v1.0
	var startingtotal = parseFloat(document.forms.orderform.Total.value);
	var optionprice = parseInt(x.value);
	if (x.checked==true) { //then they're checking the box and the price should be increased
		var newtotal = currencyformat(startingtotal+optionprice);
	}
	else if (x.checked==false) { //then they're un-checking the box and the price should be decreased
		var newtotal = currencyformat(startingtotal-optionprice);
	}
	document.forms.orderform.Total.value = newtotal;
	document.forms.orderform.DisplayTotal.value = newtotal;
}
	
	
function currencyformat(inputnumber) { //v1.0
	var inputstring = new String(inputnumber);
		if (inputstring.length==(inputstring.indexOf(".")+3)) {
			outputstring = inputstring;
		}
		if (inputstring.length>(inputstring.indexOf(".")+3)) {
			outputstring = inputstring.substr(0,(inputstring.indexOf(".")+3));
		}
		if ((inputstring.length-inputstring.indexOf("."))==2) {
			outputstring = inputstring+"0";
		}
		if (inputstring.indexOf(".")==-1) {
			outputstring = inputstring+".00";
		}
	return outputstring;
}
	
	
function DW_TimeStampIt() { //v1.0
	var myTimeStamp = new Date();
	document.forms.orderform.TimeStamp.value = myTimeStamp.getTime();
}


function setfocus(){
	document.Form.UserName.focus();
	 return true; 
}

var signon = true;

function send(){
 	if(document.Form.UserName.value == "" && signon){
        alert("Please enter your OCDLA Username.\n\nIf you've forgotten your OCDLA Username,\nPlease contact OCDLA.");
        document.Form.UserName.focus();
        document.Form.UserName.select();
        return false;
 	}

	return true;
	
}

function clearForm(){
	elems=document.forms[0].elements;
	arr=new Array();
	//window.alert(document.forms[0].elements);
	//loop through quantities and assign 0 values, where appropriate
	for(i=0; i<elems.length; i++){
		//window.alert(elems[i].name+": "+elems[i].value);
		if(elems[i].name=="quantity") elems[i].value="";
	}//
	

	return true;  
}//clearForm

function checkForm(){
	elems=document.forms[0].elements;
	arr=new Array();
	//window.alert(document.forms[0].elements);
	//loop through quantities and assign 0 values, where appropriate
	for(i=0; i<elems.length; i++){
		//window.alert(elems[i].name+": "+elems[i].value);
		if(elems[i].name=="quantity" && elems[i].value=="") elems[i].value=0;
		if(elems[i].name=="quantity" && elems[i].value=="0") elems[i].value=0;
	}//
	

	return true;  
}//checkForm



var CartLibrary = {
	loginurl : "www.ocdla.org/includes/evaluateLogin.php",
	zipgenerationurl : "www.ocdla.org/send-pdfs/generateorder_createZip.php",
	addButton : function(ajaxobj){
		if(ajaxobj.req.responseText.indexOf("Logout")==-1) return;
		href = location.protocol+"//www.ocdla.org/logout.php";
		var navlinks = document.getElementById('navlinks');
		//alert(progressIndicator);
		mylink=document.getElementById('logout');
		//else mylink = document.createElement('a');
		mylink.setAttribute('href', href);
		mylink.appendChild(document.createTextNode( 'Logout'));//ajaxobj.req.responseText ));
		//for ie we have to strip out the whitespace
		//navlinks.appendChild( document.createTextNode('|') );
		//navlinks.appendChild(mylink);
	}//addButton

}

	var protocol=/https:\/\//gi;
	var www=/www/;
	var hostname, redirect;
	
	function wwwsecure(){
	if(window.location.protocol!="https:" || window.location.hostname.search(www)==-1) {
		hostname=window.location.hostname.search(www)==-1?"www."+window.location.hostname:window.location.hostname; 
		redirect="https://"+hostname+window.location.pathname;
		window.location=redirect;
	}//if
	}//wwwsecure


function init(){
	// quit if this function has already been called
	if (arguments.callee.done) return;
	
	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;
	
	// do stuff
	P7_PMMop('p7PMM_1',0,1,-5,-5,0,0,0,1,0,3,1,1,0);
	P7_PMMinit();//revised 2010-02-09
	try{login = document.getElementById('login');
	login.href = login.href+'?ref='+location.pathname;}catch(e){ }
}


   /* for Mozilla */
   if (document.addEventListener) {
       document.addEventListener("DOMContentLoaded", init, false);
   }

   /* for other browsers */
   window.onload = init;

/*if (window.attachEvent) window.attachEvent("onload", init);
else window.onload = init;*/