//////////----MAILING LIST CHECK FUNCTIONS--------////////////////////////////////////////////////////

function showPrev(me,event){  
       document.getElementById("previewimg").src ="images/loading2.gif";
	   screenWidth = screen.width ;
       var x = 0,y = 0;
       x = event.clientX+30;
       y = event.clientY-160;
	   
       if (document.pageYOffset)
       {
           x += document.pageXOffset;
           y += document.pageYOffset;
       }
       else if(document.documentElement && document.documentElement.scrollTop)
       {
           x += document.documentElement.scrollLeft;
           y += document.documentElement.scrollTop;
       }
       else if(document.body)
       {
           x += document.body.scrollLeft;
           y += document.body.scrollTop;
       }                                      alert(x+"########screenwidth:"+screenWidth);
	   if(parseInt(screenWidth - x)<500){
	      x = x-300;
	   }                                        
	   var productPrice = me.name;
	   var productDesc  = me.alt;
	   var productTitle = me.title;  
	   
	   document.getElementById("productname").innerHTML  = productTitle;
	   document.getElementById("productprice").innerHTML = productPrice;
	   document.getElementById("productdesc").innerHTML  = productDesc;
	   
	   document.getElementById("previewimg").width   = "300";
	   document.getElementById("previewimg").height  = "300";
       
	   document.getElementById("showpreview").style.top     =y+"px";
	   document.getElementById("showpreview").style.left    =x+"px";
	   document.getElementById("showpreview").style.display ="block";                           //alert(1);
	   document.getElementById("previewimg").src = "prod_image/"+me.id+"_250300.jpg";
	   //setTimeout("closeMe()",15000);
	   }

function closeMe(){
       document.getElementById("showpreview").style.display="none";
}



function initXMLHTTPRequest() {
	var xmlHttp = null;
	try {
	    	// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
	       	// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
var deptimage = "";
 function getDeptProduct(deptcode,deptimg,deptname,count){ 
    var deptarr = document.getElementsByName("dept");
	for(var i=0;i<deptarr.length;i++){
	    deptarr[i].className="";
	}
    document.getElementById(deptcode).className = "active";  
	if(document.getElementById("checkpage")){
		
		var catarr = document.getElementById("totaldept").value;
		//alert(catarr);
		for(var i=0;i<catarr;i++){
			
			if(i==count)
				document.getElementById('subcategory_' + i).style.display="";
			else	
				document.getElementById('subcategory_' + i).style.display="none";
		
		}
		document.getElementById("productDisplayDiv").innerHTML = "<img src='images/loading.gif'>";
	    document.getElementById("deptimage").innerHTML = '<img src="images/loading.gif">';
        var xmlHttp = initXMLHTTPRequest();
		var url="getdeptproductsajax.php?deptcode="+deptcode;  
		xmlHttp.open("GET",url, true);
		xmlHttp.onreadystatechange = function () {
				if (xmlHttp.readyState == 4) {
				var xmlDoc = xmlHttp.responseXML;
				var xmlObj = xmlDoc.getElementsByTagName("products")[0]; //alert("#########"+length);
				var length=xmlObj.childNodes.length;   
				var str ="";
				var j = 1;
				var dept_name    = xmlObj.childNodes[0].childNodes[9].childNodes[0].nodeValue ;
				var dept_code    = xmlObj.childNodes[0].childNodes[10].childNodes[0].nodeValue;
				var totalproduct = xmlObj.childNodes[0].childNodes[11].childNodes[0].nodeValue;
				var count =0 ;
				for(i=0;i<length;i++)
				{
					var brand           = xmlObj.childNodes[i].childNodes[0].childNodes[0].nodeValue;    
					var productCode     = xmlObj.childNodes[i].childNodes[1].childNodes[0].nodeValue;
					var seoUrl          = xmlObj.childNodes[i].childNodes[2].childNodes[0].nodeValue;
					var productTitle    = xmlObj.childNodes[i].childNodes[3].childNodes[0].nodeValue;
					var shortname       = xmlObj.childNodes[i].childNodes[4].childNodes[0].nodeValue;
					var ourPrice        = xmlObj.childNodes[i].childNodes[5].childNodes[0].nodeValue;
					var sign            = xmlObj.childNodes[i].childNodes[6].childNodes[0].nodeValue;
					var prodImage       = xmlObj.childNodes[i].childNodes[7].childNodes[0].nodeValue;
					var shortDescr      = xmlObj.childNodes[i].childNodes[8].childNodes[0].nodeValue;
					var description     = xmlObj.childNodes[i].childNodes[12].childNodes[0].nodeValue;
					
					if(j%4 == 0){
					  str = str+
					  '<li>'+
					  '<p><a  href="'+brand+'-id-'+productCode+'-'+seoUrl+'.html" title="'+productTitle+'">'+shortname+'</a></p>'+
					  '<p class="p_price">Our Price: '+sign+''+ourPrice+'</p>'+
					  '<a  href="'+brand+'-id-'+productCode+'-'+seoUrl+'.html" >'+
					  '<img class="p_img" src="prod_image/'+prodImage+'" width="100" height="157"  alt="'+description+'" name="'+sign+''+ourPrice+'" title="'+productTitle+'" onmouseover="showPrev(this,event)" id="'+productCode+'" onmouseout="closeMe()"/>'+
					  '</a>'+
					  '<p class="p_txt">'+shortDescr+'</p>'+
					  '<img class="ad_cart" src="images/add_to_cart_b.jpg" width="106" height="45" onclick="addtocart(this,event)" id="'+productCode+'"/>'+
					  '</li>';
					}else{
					  str = str+
					  '<li style="border-right:1px dashed #DBDBDB;">'+
					  '<p><a  href="'+brand+'-id-'+productCode+'-'+seoUrl+'.html" title="'+productTitle+'">'+shortname+'</a></p>'+
					  '<p class="p_price">Our Price: '+sign+''+ourPrice+'</p>'+
					  '<a  href="'+brand+'-id-'+productCode+'-'+seoUrl+'.html" >'+
					  '<img class="p_img" src="prod_image/'+prodImage+'" width="100" height="157"  alt="'+description+'" name="'+sign+''+ourPrice+'"  title="'+productTitle+'" onmouseover="showPrev(this,event)" id="'+productCode+'" onmouseout="closeMe()"/>'+
					  '</a>'+
					  '<p class="p_txt">'+shortDescr+'</p>'+
					  '<img class="ad_cart" src="images/add_to_cart_b.jpg" width="106" height="45" onclick="addtocart(this,event)" id="'+productCode+'"/>'+
					  '</li>';
					}
					j++; 
					count++;
				}   
				document.getElementById("morediv").innerHTML ="";   
				if(dept_code != "" && totalproduct > 8){  //alert(totalproduct); 
				  document.getElementById("morediv").innerHTML = "<a href='shop-online-"+dept_name+".html' style='text-decoration:none;color:#9933FF;'>More...</a>";
				}
				str = str+"";
				deptimage = deptimg ;
				document.getElementById("productDisplayDiv").innerHTML ="";
				document.getElementById("productDisplayDiv").innerHTML = str;   
				document.getElementById("deptname").innerHTML = deptname;
				//document.getElementById("deptimage").width  = "100";
				//document.getElementById("deptimage").height = "100";
				
				document.getElementById("deptimage").innerHTML = '<img src="dept_banner/'+deptimage+'"  width="789" height="199">';
			}
		};
		xmlHttp.send(null);
   }
   else{   
	 var strurl = deptcode;
     location.href = "index.php?deptcode="+strurl;
   }
 }
 
/* function selectDept(){  
    var url = document.location.href;
	var arr = url.split("?");
	if(arr[1]){    
		var deptcodearr = arr[1].split("="); 
		if(deptcodearr[0] == "strurl"){   
			var deptcode = deptcodearr[1];
			var xmlHttp = initXMLHTTPRequest();  
			var url="getDeptAjax.php?deptcode="+deptcode;    
			xmlHttp.open("GET",url, true);            
			xmlHttp.onreadystatechange = function () {  
					if (xmlHttp.readyState == 4) {
					  var xmlDoc = xmlHttp.responseTEXT;
					}
			};
		}
	}
 }
*/ function helperMethod(){   
      //document.getElementById("deptimage").width  = "789";
	  //document.getElementById("deptimage").height = "199";
      document.getElementById("deptimage").innerHTML = '<img src="dept_banner/'+deptimage+'"  width="789" height="199">';
 }

function ckeckEmail()
{
    var emailAdd=document.getElementById("textfield2").value;
    var xmlHttp = initXMLHTTPRequest();
    var url="subscribeemail.php?textfield2="+emailAdd;  
    xmlHttp.open("GET",url, true);
	xmlHttp.onreadystatechange = function () {
	        if (xmlHttp.readyState == 4) {
			var xmlDoc = xmlHttp.responseText;
			
			document .getElementById("msg1").innerHTML=xmlDoc;
			msgIntervalId = setTimeout("timedClearMs('msg1', 'textfield2')", 5000);
			
		}
	};
	xmlHttp.send(null);
}

function changeText(elementName, eventType) {
	var value = elementName.value;
	var defaultValue =  'Enter keyword';	
	
	if(eventType=='show') {
		if(value == "") elementName.value = defaultValue;
	}
	
	if(eventType=='hide') { 
		if(value == defaultValue) elementName.value = '';
	}
}

function validMail()
{
   var emailAdd=document.getElementById("textfield2").value;
   var email_flag=true;
   var filter  =/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if (!filter.test(emailAdd))
   {            
	 email_flag=false;
   }
   if(email_flag == true)
   {
     ckeckEmail();
   }
   else{
	 document .getElementById("warning").innerHTML='<span class="bodyheadingssmall" style="margin-left:5px;"><font color="#ff0000">Please enter a valid email id.</font></span>';  
	 msgIntervalId = setTimeout("timedClearMs('warning', '')", 5000);   
   }  
   return false;
} 
function timedClearMs(objID, objID1) {
	document.getElementById(objID).innerHTML = '';
	if(objID1 != '')
		document.getElementById(objID1).value = '';
	clearTimeout(msgIntervalId);
}
///////////////////----------END OF MAILING LIST CHECK FUNCTIONS-------------////////////////////////////////////



function initializeSearch(type, isPage, multipage) {
	//alert('sd');
	if(type == 'bottom') {
		document.submitsearch.perPage.value = document.submitsearch.perPageBottom.value;
		document.submitsearch.sortBy.value  = document.submitsearch.sortByBottom.value;
		if(isPage && multipage)
			document.submitsearch.page.value  = document.submitsearch.pageBtm.value;
		else
			document.submitsearch.page.value  = 1;
		document.submitsearch.submit();
	} else if(type == 'top') {
		document.submitsearch.perPage.value = document.submitsearch.perPageTop.value;
		document.submitsearch.sortBy.value  = document.submitsearch.sortByTop.value;
		if(isPage && multipage)
			document.submitsearch.page.value  = document.submitsearch.pageTop.value;
		else
			document.submitsearch.page.value  = 1; 
		document.submitsearch.submit();
	} 
}


function verifymail() { 

   var femailAdd=document.getElementById("from").value;
   var emailAdd=document.getElementById("to").value;
   var email_flag=true;
   var filter  =/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if (!filter.test(femailAdd))
   {            
	  document .getElementById("msgf").innerHTML='<font color="#ff0000">Please Enter a valid Email Id.</font>';  
	  msgIntervalId = setTimeout("timedClearMs('msgf', '')", 5000);  
	  return false;

   }
   if (!filter.test(emailAdd))
   {            
	  document .getElementById("msgt").innerHTML='<font color="#ff0000">Please Enter a valid Email Id.</font>';  
	  msgIntervalId = setTimeout("timedClearMs('msgt', '')", 5000);  
	  return false;

   }
   
 return true;

}

function showMedImage(cnt)
{

var medImgs = document.getElementsByName("medimg[]");
for(var i=0;i<medImgs.length;i++){
	medImgs[i].style.display="none";
	
}

	medImgs[cnt].style.display="block";

	 
}