// JavaScript Document

function SimpleSwap(el,which){

  el.src=el.getAttribute(which || "origsrc");

}



function SimpleSwapSetup(){

  var x = document.getElementsByTagName("img");

  for (var i=0;i<x.length;i++){

    var oversrc = x[i].getAttribute("oversrc");

    if (!oversrc) continue;

      

    // preload image

    // comment the next two lines to disable image pre-loading

    x[i].oversrc_img = new Image();

    x[i].oversrc_img.src=oversrc;

    // set event handlers

    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");

    x[i].onmouseout = new Function("SimpleSwap(this);");

    // save original src

    x[i].setAttribute("origsrc",x[i].src);

  }

}



var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};

window.onload = function(){

	PreSimpleSwapOnload(); SimpleSwapSetup(); 

	if(document.getElementById("subCont") != null)

		ContentDivHeight();	ContentDivHeight3();

	if(document.getElementById("subCont") == null && document.getElementById("listingRightBody") == null && document.getElementById("photoCont") != null)

		ContentDivHeight();

	if(document.getElementById("listingRightBody") != null && document.getElementById("subCont") == null)

		ContentDivHeight2();		

}



function ContentDivHeight(){

	if(document.getElementById("subCont") != null || document.getElementById("rightBodyContent") != null){

		var photoHeight = document.getElementById("photoCont").offsetHeight;

		var subCont = document.getElementById("subCont");

		if(subCont != null){

			var subContHeight = subCont.offsetHeight;

			var padd = 15;

		}else {

			var subContHeight = 0;

			var padd = 20;

		}

		var right = document.getElementById("rightBodyContent");

		var rightHeight = right.offsetHeight;	

		leftHeight = photoHeight + subContHeight;	

		if(leftHeight < rightHeight) subCont.style.height = rightHeight - photoHeight - 35 + 'px';

		else right.style.height = leftHeight - padd + 'px';

	}

}



function ContentDivHeight2(){

	if(document.getElementById("listingLeftBody") != null && document.getElementById("listingRightBody") != null){

		var left = document.getElementById("listingLeftBody");

		var leftHeight = left.offsetHeight;

		var right = document.getElementById("listingRightBody");

		var rightHeight = right.offsetHeight;

		if(leftHeight > rightHeight) right.style.height = leftHeight + 'px';

	}

}



function ContentDivHeight3(){

	if(document.getElementById("listingRightBody") != null && document.getElementById("rightBodyContent") != null){

		var left = document.getElementById("rightBodyContent");

		var leftHeight = left.offsetHeight;

		var right = document.getElementById("listingRightBody");

		var rightHeight = right.offsetHeight;

		if(leftHeight > rightHeight) right.style.height = leftHeight - 20 + 'px';

	}

}



function clearFrmText(name,val,str){

	if(val == 0){		

		if(document.getElementById(name).value == str){

			document.getElementById(name).value = "";

		}

	} else if(val == 1){

		if(document.getElementById(name).value == ""){

			document.getElementById(name).value = str;

		}

	}	

}



function echeck(str){ //Check email address

	var at="@"

	var dot="."

	var lat=str.indexOf(at)

	var lstr=str.length

	var ldot=str.indexOf(dot)

	if (str.indexOf(at)==-1){

	   alert("Invalid E-mail ID")

	   return false

	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

	   alert("Invalid E-mail ID")

	   return false

	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

	    alert("Invalid E-mail ID")

	    return false

	}

	 if (str.indexOf(at,(lat+1))!=-1){

	    alert("Invalid E-mail ID")

	    return false

	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

	    alert("Invalid E-mail ID")

	    return false

	 }

	 if (str.indexOf(dot,(lat+2))==-1){

	    alert("Invalid E-mail ID")

	    return false

	 }

	 if (str.indexOf(" ")!=-1){

	    alert("Invalid E-mail ID")

	    return false

	 }

 	return true					

}

function checkfrm(){

	var fname  = document.contact.fname;

	var lname  = document.contact.lname;

	var email  = document.contact.email;

	var option = new Array();

	var j = 0;

	for(i=0; i<=4; i++){

		box = eval("document.contact.option" + i); 

		if(box.checked == true) {			

			option[j] = document.getElementById('option'+i).value;

			j++;

		}

	}

	if((fname.value=="")||(fname.value==null)){

		alert("Please enter your first name!");

		fname.focus();

		return false

	}else if ((lname.value==null)||(lname.value=="")){

		alert("Please enter your last name!");

		lname.focus()

		return false

	}else if ((email.value==null)||(email.value=="")){

		alert("Please enter your E-mail ID!");

		email.focus()

		return false

	}else if(echeck(email.value)==false){

		email.value="";

		email.focus();

		return false

	}

	document.contact.idp.value = option;

	return true

}



function checkfrm2(){

	var name  = document.mailForm.name;

	var email  = document.mailForm.from;

	var to  = document.mailForm.to;

	if((name.value=="")||(name.value==null)){

		alert("Please enter your name!");

		name.focus();

		return false

	}else if ((email.value==null)||(email.value=="")){

		alert("Please enter your E-mail ID!");

		email.focus()

		return false

	}else if(echeck(email.value)==false){

		email.value="";

		email.focus();

		return false

	}else if ((to.value==null)||(to.value=="")){

		alert("Please enter sending E-mail ID!");

		to.focus()

		return false

	}else if(echeck(to.value)==false){

		to.value="";

		to.focus();

		return false

	}

	return true

}





function tabs(i,n) {

	var img_src = "images/tabs/";

	for (var j = 0; j < n; j ++) {

		if (j == i) {

		   document.getElementById('container'+j).style.display = "";

		   if(i == 1) document.getElementById('container'+j).innerHTML = document.getElementById('container'+j).innerHTML;

		   document.getElementById('pane'+j).src = img_src+'btn_'+i+'_over.jpg';

		} else {

		   document.getElementById('container'+j).style.display = "none";

		   document.getElementById('pane'+j).src = img_src+'btn_'+j+'.jpg';

		}

	}

}