
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////Product Details Related Funnction Starts Here///////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getBrowserHeight() {
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	//arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	//return arrayPageSize;
	
	return { width: parseInt(pageWidth), height: parseInt(pageHeight) };
}  

function setLayerPosition() {
	var shadow = document.getElementById("divShadowLayer");
	var divProductDetail = document.getElementById("divProductDetails");

	var bws = getBrowserHeight();
	shadow.style.width = bws.width + "px";
	shadow.style.height = bws.height + "px";

	divProductDetail.style.left = parseInt((bws.width - 350) / 2);
	divProductDetail.style.top = parseInt((bws.height) / 2);
	
	shadow = null;
	divProductDetail = null;
}
	

	
function hideProductDetailBox() {
	var shadow = document.getElementById("divShadowLayer");
	var divProductDetail = document.getElementById("divProductDetails");
	
	// Removing errorclass from textfileds
	document.getElementById("txtitemno").className='textfield';
	document.getElementById("txtsize").className='textfield';
	document.getElementById("txtsizeunit").className='textfield';
	document.getElementById("txtweight").className='textfield';
	document.getElementById("txtweightunit").className='textfield';
	document.getElementById("txtprice").className='textfield';
	
	
	new Effect.Appear('divShadowLayer',{ duration: 0.5, direction: 'center', from: 0.8, to: 0.0});
	//new Effect.Appear('divProductDetails',{ duration: 0.5, direction: 'center', from: 1.0, to: 0.0});
	//shadow.style.display = "none"; 
	//divProductDetail.style.display = "none";
	setTimeout("document.getElementById('divProductDetails').style.display='none';document.getElementById('divShadowLayer').style.display='none'; document.getElementById('rel_products').style.visibility='visible'; ",400); 

	shadow = null;
	divProductDetail = null; 
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////	
/////////////////////////////////////////// Search Related functions starts here///////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////

function setCookie(name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + ";path=/";
}

function getCookie(name){
	if (document.cookie.length>0)
	  {
	  start=document.cookie.indexOf(name + "=");
	  if (start!=-1){
			
			start=start + name.length+1;
			end=document.cookie.indexOf(";",start);
			if (end==-1) end=document.cookie.length;
			//alert(unescape(document.cookie.substring(start,end)));
			return unescape(document.cookie.substring(start,end));
			
		}
	  }
	return "";
}

function expandSearch(SITE_URL){
	state = getCookie('sch');
	if(state==1){	
		setCookie('sch', '0', 1);
	}else if(state==0){
		setCookie('sch', '1', 1);
	}
	checkstate(SITE_URL);	
}

function checkstate(SITE_URL){
	if(document.getElementById('search')){
		state = getCookie('sch');
		if(state==1){
			document.getElementById('search').style.display = '';
			document.getElementById('img').innerHTML = '<img border="0" src="'+SITE_URL+'images/icons/minus.png">';
		}else{
			document.getElementById('search').style.display = 'none';
			document.getElementById('img').innerHTML = '<img border="0" src="'+SITE_URL+'images/icons/plus.gif">';
		}
	}//endif
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////Search Functions Ends Here/////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////




////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////Get Page Size function starts here//////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

function getPPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////Get Page Size function ends here////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Function for populating values returned by ajax function in case of edit record starts here
function get_values(status) {
	var val_arr = status.split("####");
	document.getElementById("txtitemno").value = val_arr[0];
	document.getElementById("txtsize").value = val_arr[1];
	document.getElementById("txtsizeunit").value = val_arr[2];
	document.getElementById("txtweight").value = val_arr[3];
	document.getElementById(val_arr[4]).selected = "selected";
	document.getElementById("txtprice").value = val_arr[5];
	if(val_arr[6]!=0)
		dropdownSelect('ddItem__'+val_arr[6],val_arr[6],'');
	else 
		dropdownSelect('ddItem__0',0,'');
	//alert(val_arr[6]);
	//var color_id = val_arr[6];
	//dropdownSelect('ddItem__'+val_arr[6],val_arr[6],'');
	/*if(val_arr[6]!=0)
		document.getElementById(val_arr[6]).selected = "selected";
	else {
		for(var i=0; i<color_arr.length; i++)
			document.getElementById(color_arr[i]).checked = "";
	}*/
		
	if(val_arr[7]==1)
		document.getElementById('yes').checked = "checked";
}
// Function for populating values returned by ajax function in case of edit record ends here


function removeFromArray(val, ar){
	s = String(ar);
	// remove if not first item (global search)
	reRemove = new RegExp(","+val,"g");
	s = s.replace(reRemove,"");
	// remove if at start of array
	reRemove = new RegExp("^"+val+",");
	s = s.replace(reRemove,"");
	// remove if only item
	reRemove = new RegExp("^"+val+"$");
	s = s.replace(reRemove,"");
	return new Array(s);
}
function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\0/g,'\0');
	str=str.replace(/\\\\/g,'\\');
	return str;
}

function CheckAll()
{
	var i;
	for (i = 0; i < document.getElementById("rel_products").length; i++)
	{
		//alert(document.frm_add_product.selrealtors.value);
		document.frm_add_product.rel_products[i].selected = true;
	}
	document.getElementById("rel_products").focus();
}
function UnCheckAll()
{
	var i;
	for (i = 0; i < document.getElementById("rel_products").length; i++)
	{
	document.frm_add_product.rel_products[i].selected = false;
	}
	document.getElementById("rel_products").focus();
}

function selectItem(id){
	var element = document.getElementById(id);
	var isChecked = false;
	var colors = document.frm_add_size["color"];
	if(element.checked == true){
		element.checked = false;
		document.getElementById('rw'+id).className = 'normal';
	}else if(element.checked == false){
		element.checked =  true;
		document.getElementById('rw'+id).className = 'selected';
	}
	
	for(i=0;i<colors.length;i++){
		if(colors[i].checked==true)
			isChecked = true;
	}	
}//end function

////////////////////////////////////////////////////////////////////////////////////////
//////////////////Function to display selected related Products Starts Here///////////
//////////////////////////////////////////////////////////////////////////////////////
 var MaxPsize = 5;
 function showSelectedRelatedProducts(){
	var len = document.getElementById('rel_products').length;
	checkedCnt =0;
	document.getElementById('divSelectedRelatedProduct').innerHTML = '';
	for(i=0;i<len;i++){
		if(document.getElementById('rel_products').options[i].selected==true){
			checkedCnt++;
			if(checkedCnt > MaxPsize){ 
				document.getElementById('divSelectedRelatedProduct').innerHTML = 'More than '+MaxPsize+' Products are selected.';
			    document.getElementById('rel_products').setAttribute('required', 1);
				break;
			}else{						
				document.getElementById('divSelectedRelatedProduct').innerHTML +=  '<div style="line-height:16px;">'+document.getElementById('rel_products').options[i].text+'</div>';
				document.getElementById('rel_products').setAttribute('required', 0);
			}
		}
	}//edn for
}//end function
////////////////////////////////////////////////////////////////////////////////////////


function tabs(id,obj){
		document.getElementById(id).className='home_tabs_hover';
		obj.onmouseout=function () {
			document.getElementById(id).className='home_tabs_out';
		}
	}

/*slide*/
var menu_effect=0;
var previous_obj;
var pre_head_obj;
var pre_block_obj;
function show_block(head_obj,block_obj)
{ //alert(head_obj);
		if(document.getElementById(block_obj).style.display=='') {
			if(menu_effect==0) {
				menu_effect=1;
				//new Effect.SlideUp(block_obj , { duration: 0.7});
				document.getElementById(block_obj).style.display='none';
				previous_obj=head_obj;
				setTimeout("hide_block();", 700);
				pre_head_obj=false;
			}
		} else {			
			if(menu_effect==0) {
				menu_effect=1;
				//new Effect.SlideDown(block_obj , { duration: 0.7});
				document.getElementById(block_obj).style.display='';
				head_obj.className='current';
				if(typeof(pre_head_obj)!="undefined") {
					if(pre_head_obj) {
						//new Effect.SlideUp(pre_block_obj , { duration: 0.7});
						document.getElementById(pre_block_obj).style.display='none';
						previous_obj=pre_head_obj;
						setTimeout("hide_block();", 700);
					}
				}
				pre_head_obj=head_obj;
				pre_block_obj=block_obj;
				setTimeout("menu_effect=0", 700);
			}
			
		}
 }
function hide_block() {
		previous_obj.className='';
		menu_effect=0;
}

/*slide*/

function showBox(name,name_hide) {
		if(typeof(name_hide)!="undefined") {
			if(name_hide!="") {
				new Effect.Opacity("div_"+name_hide,{duration:.8,from:1,to:0});
				setTimeout('$("div_'+name_hide+'").style.visibility="hidden";',800);
			}
		}
		selectBoxFix(true);
		var page_arr = getPageSize();
		$("div_body_disable").style.width=page_arr[0]+"px";
		$("div_body_disable").style.height=page_arr[1]+"px";
		$("div_body_disable").style.display="";
		$("div_"+name).style.zIndex=1001;
		$("div_"+name).style.top = ((page_arr[3]/2) - ($("div_"+name).offsetHeight/2)) + "px";
		$("div_"+name).style.left = ((page_arr[2]/2) - ($("div_"+name).offsetWidth/2)) + "px";
		new Effect.Opacity("div_"+name,{duration:.8,from:0,to:1});
		setTimeout('$("div_'+name+'").style.visibility="visible";',100);
	}
	function hideBox(name) {
		
		new Effect.Opacity("div_"+name,{duration:.8,from:1,to:0});
		setTimeout('$("div_'+name+'").style.visibility="hidden";$("div_body_disable").style.display="none";selectBoxFix(false);',800);
		//$("div_"+name).style.visibility="hidden";
		//$("div_body_disable").style.display="none";
	}
	function selectBoxFix(show){
		if(navigator.appName=='Microsoft Internet Explorer' && navigator.appVersion.indexOf('MSIE 6.0')>=0){
			var all_div=document.getElementsByTagName('select');
			div_len=all_div.length;
			for(var i=0; i<div_len;i++) {
				if(show) {
					if(typeof(all_div[i].rel)=="undefined") {
						 if(all_div[i].style.display!="none") {
							 all_div[i].rel="v";
							 all_div[i].style.display="none";
						 } else {
							 all_div[i].rel="i";
						 }
					} else if(all_div[i].rel=="v") {
						all_div[i].style.display="none";
					}
				} else {
					if(all_div[i].rel=="v") {
						all_div[i].style.display="";
					}
				}
			}
		}
	}
	
	function msieversion()
   {
      var ua = window.navigator.userAgent
      var msie = ua.indexOf ( "MSIE " )

      if ( msie > 0 )      // If Internet Explorer, return version number
         return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )))
      else                 // If another browser, return 0
         return 0

   }
