var imageUrl = siteUrl+"images/";
var emText = "Click to Email";
var em = "o";
var emDom = "";
var emDomType = "";
var inputWin;
function getObject(obj) {
	var theObj
	if (document.layers) {if (typeof obj == "string") {return document.layers[obj]} else {return obj}}
	if (document.all) {if (typeof obj == "string") {return document.all(obj).style} else {return obj.style}}
	if (document.getElementById) {if (typeof obj == "string") {return document.getElementById(obj).style} else {return obj.style}}
	return null
}
function getElObject(obj){
    var theObj
	if (document.layers) {if (typeof obj == "string") {return document.obj} else {return obj}}
	if (document.all) {if (typeof obj == "string") {return document.all(obj)} else {return obj}}
	if (document.getElementById) {if (typeof obj == "string") {return document.getElementById(obj)} else {return obj}}
	return null
}

function turn_off(ImageName) {
	if (document.images != null) {
		   getElObject(ImageName).src = eval(ImageName + ".src");
	}
}

function turn_over(ImageName) {
	if (document.images != null) {
		  getElObject(ImageName).src = eval(ImageName + "_on.src");
	}
}

function turn_on(ImageName) {

	if (document.images != null) {
		   getElObject(ImageName).src = eval(ImageName + "_down.src");		
	}
}
function show(showobj) {
	showobj.visibility = "visible"
}
function hide(hideobj) {
	hideobj.visibility = "hidden"
}


function searchSite(){
	getElObject("search_products").submit();

}


if (document.images) {

top_nav_1 =  new Image(); top_nav_1.src = imageUrl+"top_nav_1.gif";
top_nav_1_over =  new Image(); top_nav_1_over.src = imageUrl+"top_nav_1_over.gif";

top_nav_2 =  new Image(); top_nav_2.src = imageUrl+"top_nav_2.gif";
top_nav_2_over =  new Image(); top_nav_2_over.src = imageUrl+"top_nav_2_over.gif";

top_nav_3 =  new Image(); top_nav_3.src = imageUrl+"top_nav_3.gif";
top_nav_3_over =  new Image(); top_nav_3_over.src = imageUrl+"top_nav_3_over.gif";


}

function viewImage(cId){
		 openInputWind(siteUrl+"view-image.php?cid="+cId,720,600);
}  

function viewOrder(){
		 openInputWind(siteUrl+"view-details.php",720,600);
} 
function viewSalesOrder(sid){
		 openInputWind(siteUrl+"customer-area/view-details.php?sid="+sid,720,600);
} 
function openInputWind(thsUrl,winWidth,winHeight){
  scrLeft = typeof window.screenLeft != 'undefined' ? window.screenLeft : window.screenX;
  scrTop = typeof window.screenTop != 'undefined' ? window.screenTop - 22 : window.screenY;
		 if (inputWin && inputWin.open && !inputWin.closed) inputWin.close();

		 inputWin = window.open(thsUrl,"","top="+(scrTop+30)+",left="+(scrLeft+30)+",height="+winHeight+",width="+winWidth+",statusbar,scrollbars,resizable")
} 

function openFullWin(pgUrl){
   window.open(pgUrl);
}
 
function show(showobj) {
	showobj.visibility = "visible"
}
function hide(hideobj) {
	hideobj.visibility = "hidden"
}

function writeEA(){
var cnt = "sales";
var em = "sales";
var emH = "dragonflyfabrics.co.uk";
document.write("<a href=" + "mail" + "to:" + em + "@" + emH + " class='page_link'>" + cnt + "@"+ emH+"</a>" + ".")
}

function add_basket(pId){
  var tranferOk = true;
  if (getElObject("qnt_"+pId) != null){
     pQnty = getElObject("qnt_"+pId).value;
     pQnty = trimSpaces(pQnty);
	 pQnty = Math.ceil(pQnty*10)/10;
	 if (pQnty == "0" || !isNumeric(pQnty)){
	 	alert ("Quantity must be a number greater than zero.");
		tranferOk = false;	 
	 }
  }else{
     pQnty = 1;
  }
  if (tranferOk){
     window.location = siteUrl+"basket.php?pid="+pId+"&qnt="+pQnty;
  }

}
 
function trimSpaces(str) { 
    
    while (str.substring(0,1) == ' ') 
        str = str.substring(1, str.length);

    while (str.substring(str.length-1,str.length) == ' ')
        str = str.substring(0, str.length-1);

   return str;
} 

function isNumeric(str) {
   var strValidChars = "1234567890.";
   var strChar;
   var blnResult = true;

   if (str.length == 0) return false;
 
   for (i = 0; i < str.length && blnResult == true; i++)
      {
      strChar = str.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

