document.domain = "doveonline.com";

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=["MAIN"]

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"


var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 32 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers
//alert(FFextraHeight);

function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}

function resizeIframe(frameid){
	var currentfr=document.getElementById(frameid)
	if (currentfr && !window.opera){
		currentfr.style.display="block";
		if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) { //ns6 syntax
			currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
		}
		else if (currentfr.Document && currentfr.Document.body.scrollHeight) { //ie5+ syntax
			currentfr.height = currentfr.Document.body.scrollHeight;
		}
		if (currentfr.addEventListener) {
			currentfr.addEventListener("load", readjustIframe, false);
		}
		else if (currentfr.attachEvent){
			currentfr.detachEvent("onload", readjustIframe); // Bug fix line
			currentfr.attachEvent("onload", readjustIframe);
		}
	}
}

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
if (document.getElementById)
document.getElementById(iframeid).src=url
}


if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller

function SetFocus()
{
	var NumElements=document.searchform.elements.length;
	for (i=0; i<NumElements;i++)
	{
   		if (document.searchform.elements[i].type=="select" ||
       		document.searchform.elements[i].type=="radio" ||
        	document.searchform.elements[i].type=="checkbox" ||
        	document.searchform.elements[i].type=="textarea" ||
       		document.searchform.elements[i].type=="text")

    	{
        	if (document.searchform.elements[i].value!=" ")
             	document.searchform.elements[i].select();
             	document.searchform.elements[i].focus();
            	break;
    		}
		}
}

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_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_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 Home() { 
	document.emptyform.method = "GET";
	document.emptyform.action = "http://www.doveonline.com/";
	document.emptyform.submit();
}

function OrderCenter(sessionkey) { 
	document.emptyform.method = "GET";
	document.emptyform.action = "http://www.doveonline.com/ordercenter.php";
	document.emptyform.submit();
}  

function Login(sessionkey) { 
	document.emptyform.method = "GET";
	document.emptyform.action = "https://www.doveonline.com/login.php";
	document.emptyform.submit();
}

function Logout(sessionkey) { 
	document.emptyform.method = "GET";
	document.emptyform.action = "https://www.doveonline.com/logout.php";
	document.emptyform.submit();
}

function Register(sessionkey) { 
	document.emptyform.method = "GET";
	document.emptyform.action = "https://www.doveonline.com/register.php";
	document.emptyform.submit();
}

function NewUser(sessionkey) { 
	document.emptyform.method = "GET";
	document.emptyform.action = "http://www.doveonline.com/registration-complete.php";
	document.emptyform.submit();
}

function ViewCart(sessionkey) { 
	document.emptyform.method = "GET";
	document.emptyform.action = "http://www.doveonline.com/cart.php";
	document.emptyform.submit();
} 

function Checkout(sessionkey) { 
	document.emptyform.method = "GET";
	document.emptyform.action = "https://www.doveonline.com/checkout.php";
	document.emptyform.submit();
}

function OrderInquiry(sessionkey) { 
	document.emptyform.method = "GET";
	document.emptyform.action = "http://www.doveonline.com/orders.php";
	document.emptyform.submit();
}

function AccountInquiry(sessionkey) { 
	document.emptyform.method = "GET";
	document.emptyform.action = "http://www.doveonline.com/account.php";
	document.emptyform.submit();
}

function Favorites(sessionkey) { 
	document.emptyform.method = "GET";
	document.emptyform.action = "http://www.doveonline.com/favorites.php";
	document.emptyform.submit();
} 

function History(sessionkey) { 
	document.emptyform.method = "GET";
	document.emptyform.action = "http://www.doveonline.com/history.php";
	document.emptyform.submit();
} 

function ProductDetail(sessionkey,item,desc,desc2) { 
	document.productform.ITEM.value = item;
	document.productform.DESC.value = desc;
	document.productform.DESC2.value = desc2;
	document.productform.method = "GET";
	document.productform.action = "http://www.doveonline.com/item.php";
	document.productform.submit();
} 

function BackError(sessionkey) { 
	document.emptyform.method = "GET";
	document.emptyform.action = "http://www.doveonline.com/warning.php";
	document.emptyform.submit();
} 

function SelectAccount(sessionkey) { 
	document.emptyform.method = "GET";
	document.emptyform.action = "http://www.doveonline.com/selact.php";
	document.emptyform.submit();
} 

function ThankYou(sessionkey,lstwseq) { 
	document.thankyouform.LSTWSEQ.value = lstwseq;
	document.thankyouform.method = "GET";
	document.thankyouform.action = "https://www.doveonline.com/thankyou.php";
	document.thankyouform.submit();
} 

function QuoteRequest(sessionkey,item,mfg) { 
	document.quoteform.ITEM.value = item;
	document.quoteform.MFG.value = mfg;
	document.quoteform.method = "GET";
	document.quoteform.action = "http://www.doveonline.com/quote/req-quote.php";
	document.quoteform.submit();
} 

function NAVreload() { 
	loadURL('navbar.php','NAV');
} 

function pviiClassNew(obj, new_style) {
    obj.className = new_style;
}

function loadURL(url, div) {
	getURL(url,div);
	return false;
}

function getURL(url, target) {
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {showURL(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
  else
  {
	alert("Your browser does not support XMLHTTP.")
  }   
}  

function showURL(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML=" loadURL Error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}

function CategorySearch(sessionkey,cat1,cat2,cat3) { 
	document.categoryform.method = "GET";
	document.categoryform.action = "http://www.doveonline.com/searchpage.php";
	document.categoryform.CAT1.value = cat1;
	document.categoryform.CAT2.value = cat2;
	document.categoryform.CAT3.value = cat3;
	document.categoryform.submit();
}  
 
function ProductSearch(sessionkey) { 
	document.searchform.method = "GET";
	document.searchform.action = "http://www.doveonline.com/searchpage.php";
	document.searchform.submit();
} 

function ProductSearch2(sessionkey) { 
	document.searchform2.method = "GET";
	document.searchform2.action = "http://www.doveonline.com/searchpage.php";
	document.searchform2.submit();
} 

function ToTop() { 
	self.scrollTo(0,0);
}

function checkQty(qty,mult) {

   x = qty.value;
   if (x != parseInt(x)) {
      x = parseInt(x);
      if (isNaN(x)) {x=0;}
      qty.value = x;
   }

   y = mult;
   if (isNaN(y) || (y == 0) ) {y=1;}

   z = x % y;
   if (z != 0) {
      var msg = 'Please order in multiples of ' + mult;
      alert(msg);
      qty.value = 0;
      qty.focus();
      qty.select();
      return false;
   }

} 

function OrderNow(sessionkey,Item,QtyName) {
	var Qty = "";
	var NumElements=document.orderform.elements.length;
	for (i=0; i<NumElements;i++) {
		if (document.orderform.elements[i].name == QtyName) {
			Qty = document.orderform.elements[i].value;
			document.orderform.elements[i].value = "";
		}
	}

	var msg = "";
	var str = "";
	var lre = /^\s*/;

	str = Qty;
	str = str.replace(lre, "");
	if( parseInt(Qty) < 1 || str == "" || str.length < 1) {
		msg = msg + "\nQuantity is required";
	}

	if (msg != "") {
		msg = "Please correct the following errors" + msg;
		alert(msg);
		return;
	}
	
	window.frames.MAIN.phpOrderNow(sessionkey,Item,Qty);	
	
	return false;
}

function AddFavorite(sessionkey,Item,Desc1,Desc2) {
	window.frames.MAIN.phpAddFavorite(sessionkey,Item,Desc1,Desc2);
	return false;
}

function RemoveFavorite(sessionkey,Item,Desc1,Desc2) {
	window.frames.MAIN.phpRemoveFavorite(sessionkey,Item,Desc1,Desc2);
	return false;
}

function GetSeq() {
	
	// To disable caching
	tmpSeq=parseInt((Math.random()*100000)+1,10);
	tmpSeq2 =String(tmpSeq);
	for (x=0; x<31;x++){
		tmpSeq2 = tmpSeq2 + " ";
	}

	mySeq = "";
	for (x=0; x<30;x++){
		y = x + 1;
		z = tmpSeq2.substring(x,y);
		if (z==" "){
			z = "_";
		}
		mySeq = mySeq + z;
	}
	// End

	return mySeq;

}

function refreshFRAME(response) {
	document.getElementById("divFRAME").innerHTML = response;
}
	

