// JavaScript Document
var child1;

function replace_prod_thumb(image){
	document.getElementById('main_prod_image').src = '../images/loader.gif';
	document.getElementById('main_prod_image').src = image;
}

function enable_delete_button(id){
	if(document.getElementById('delete_' + id).disabled == true){
		document.getElementById('delete_' + id).disabled = false;
	}
	else if(document.getElementById('delete_' + id).disabled == false){
		document.getElementById('delete_' + id).disabled = true;
	}
}
function checksearch() {
	if (document.searchform.query.value == " Search") {
		alert("Please enter a search word before pressing 'GO'.");
		return false;
	}
	else if (document.searchform.query.value == "") {
		alert("Please enter a search word before pressing 'GO'.");
		return false;
	}
	else {
		showsearchloading();
		return true;
	}
	return false;
}
function showsearchloading() {
	//setTimeout(showsearchloading,1000); 
	if (! document.getElementById('spinnerdiv')) {
		
		spinnerdiv = document.createElement('div');
		spinnerdiv.setAttribute('id', 'spinnerdiv');
		spinnerdiv.setAttribute('class', 'spinner');
		spinnerdiv.setAttribute('className', 'spinner');
		spinnerdiv.innerHTML = "<h1>Searching ...</h1>";
		document.body.appendChild(spinnerdiv);
	}
} 
function fillsearch() {
	if (document.searchform.query.value == "") {
		window.document.searchform.query.value = " Search";
	}
}
function clearsearch() {
	if (document.searchform.query.value == " Search") {
		window.document.searchform.query.value = "";
	}
}
function submitsearch (){
	if(!checksearch()) return;
	document.searchform.submit();
}

function contactus_validation(emailField, emailAlert, queryField, queryAlert){
	
	val1 = validate_email(emailField,emailAlert);
	val2 = validate_required(queryField, queryAlert);
	
	if(val1 == false || val2 == false){
		return false
	}
	else {	
		return true;
	}
}
function validate_required(field,alerttxt){
	with (field){
		//doubleQotPos = value.lastIndexOf("\"")
		//singleQotPos = value.lastIndexOf("'")
		//|| doubleQotPos >= 0 || singleQotPos >= 0
		if (value == null || value == ""){
			alert(alerttxt);
			return false
		} 
		else { 
			return true; 
		}
	}
}

function validate_email(field,alerttxt){
	with (field){
		apos=value.indexOf("@")
		dotpos=value.lastIndexOf(".")
		doubleQotPos = value.lastIndexOf("\"")
		singleQotPos = value.lastIndexOf("'")
		
		if (apos < 1 || dotpos-apos < 2 || value == null || value == "" || doubleQotPos >= 0 || singleQotPos >= 0){
			alert(alerttxt);
			return false;
		} 
		else { 
			return true;
		}
	}
}

function validate_form(thisform){
	with (thisform){
		if (validate_required(userid,"UserID contains an invalid character or is missig a required character")==false){
			userid.focus();
			return false
		}
		if (validate_required(password,"Password contains an invalid character or is missig a required character")==false){
			password.focus();
			return false
		}
		if (validate_email(email,"Email contains an invalid character or is missig a required character")==false){
			email.focus();
			return false
		}
	}
}
function showuploading() {
	//setTimeout(showsearchloading,1000); 
	if (! document.getElementById('spinnerdiv')) {
		
		spinnerdiv = document.createElement('div');
		spinnerdiv.setAttribute('id', 'spinnerdiv');
		spinnerdiv.setAttribute('class', 'spinner');
		spinnerdiv.innerHTML = "<h1>Uploading ...</h1>";
		document.body.appendChild(spinnerdiv);
	}
} 
function printpage() {
	print();
}

function checkboxes () {
	var relations = window.opener.document.getElementById('add_item_frm').product_relations.value;
	var relArray = relations.split(",");
	
	for(i=1; i < relArray.length; i++) 
	{
		if(document.getElementById(relArray[i])){
			document.getElementById(relArray[i]).check.checked = true;
		}
	}
}

function openwindow(path){
  	child1 = open(path,'windowname','width=800,height=600,scrollbars,resizable');
    //w.document.write("This is a new window");
	//w.document.write("<img src='" + document.getElementById('building_image').value + "'>");
	//w.document.write(document.getElementById('building_image').value);
	//var relations = document.getElementById('add_item_frm').product_relations.value;
	//var relArray = relations.split(",");
		
	//for(a in relArray) 
	//{
		//child1.document.getElementById(relArray[a]).checked = true;
	//}
}

function addtoparent(id){
	var relations = window.opener.document.getElementById('add_item_frm').product_relations.value;
	var relArray = relations.split(",");
	var action = "yes";
	
	for(i=1; i < relArray.length; i++) 
	{
		if(relArray[i] == id) {
			action = "no";
			newRelArray1 = relArray.slice(1, i);
			newRelArray2 = relArray.slice(i+1, relArray.length);
			newRelArray = newRelArray1.concat(newRelArray2);
		}
	}
	
	if(action == "yes") {
  		window.opener.document.getElementById('add_item_frm').product_relations.value +=  "," + id;
	}
	
	if(action == "no") {
		window.opener.document.getElementById('add_item_frm').product_relations.value = "," + newRelArray.join();
	}
}


function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
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_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_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];}
}