// JavaScript Document

var xmlHttp

function showStates(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
 	 alert ("Browser does not support HTTP Request")
  	return
  } 
var url="getStateInfo.php"
url=url+"?id="+str+"&st=1";
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
   document.getElementById("txtHint").innerHTML="";
   document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
 } 
}

function showStatesShip(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
 	 alert ("Browser does not support HTTP Request")
  	return
  } 
var url="getStateInfo.php"
url=url+"?id="+str+"&st=2";
xmlHttp.onreadystatechange=stateChangedship 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
} 

function stateChangedship() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
   document.getElementById("txtHint_Ship").innerHTML="";
   document.getElementById("txtHint_Ship").innerHTML=xmlHttp.responseText 
 } 
}


/**
* A function to call the product's fabric informatiion and to add it to template "Click to Buy" Product Info section.
* Added by Vikas Dt : 8 Jan 10
**/

// declare a global variable
var intTextBox=0;
var txtbox_cnt=0; 
var cnt = 0;
var show_prodinfo_id = "";

function addToProductInfo(product_id, product_image_id,SITENAME)
{
    
	//Assign product image id
	show_prodinfo_id = product_image_id;
		
	var prod_selected = document.getElementById("select_prod_"+product_image_id).checked ;
	
	if(prod_selected == true)
	{
		intTextBox = intTextBox + 1;
		
		cnt++; 
		
		if(cnt > 0)
		{
		   document.getElementById('show_prodinfo').style.display = 'none';
		   document.getElementById('add_to_cartbtn').style.display = 'block';
		}
		
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		  {
			 alert ("Browser does not support HTTP Request")
			return
		  } 
		var url=SITENAME+"getProdImgInfo.php";
		url=url+"?product_id="+product_id+"&product_image_id="+product_image_id+"&intTextBox="+intTextBox;
		xmlHttp.onreadystatechange=stateChangedProdInfo 
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)	
	}
	else
	{
		removeElement(show_prodinfo_id);
		
		if(cnt == 0)
			{
			  document.getElementById('show_prodinfo').style.display = 'block';
			   document.getElementById('add_to_cartbtn').style.display = 'none';
			 //document.getElementById('show_prodinfo').innerHTML = '<div class="temp_text">Product Info:</div><div class="prod_info"><div class="prod_txt1">You have not selected a product yet.</div></div><div class="clear"></div><div class="quantity"></div>';
			}
		
	}

}

function stateChangedProdInfo() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
   	var contentID = document.getElementById('prodInfo_content');
	
	//Create new eleement "div" to show the product info.
	var newTBDiv = document.createElement('div');
	
	// User intTextBox which is assigned with product image id
	newTBDiv.setAttribute('id','show_prodinfo_'+show_prodinfo_id);	
	
	newTBDiv.innerHTML = xmlHttp.responseText;
	contentID.appendChild(newTBDiv);	
 } 
}

//FUNCTION TO REMOVE TEXT BOX ELEMENT
function removeElement(txtdivid)
{
//if(intTextBox != 0)
//{
var contentID = document.getElementById('prodInfo_content');
contentID.removeChild(document.getElementById('show_prodinfo_'+txtdivid));
txtbox_cnt = cnt-1;
cnt = txtbox_cnt;
//}

}

function check11()
{	
	if(txtbox_cnt > 0)
	{
		var txtbox_cnt1 = txtbox_cnt;
	}
	else
	{
		var txtbox_cnt1 = intTextBox;
	}
	
	// Check the Quantity
	var qty_box_flg = 0;
	for(i=1; i <= txtbox_cnt1; i++)
	{
		if(document.getElementById("quantity_"+i).value == "")
		{
			qty_box_flg = 1;
			document.getElementById("quantity_"+i).focus();
		}
	}
	
	if(qty_box_flg > 0)
	{
		alert("Please enter quantity of selected item(s)");
		return false;
	}
	
	// Check the Sizes
	var size_box_flg = 0;
	for(j=1; j <= txtbox_cnt1; j++)
	{		
		if(document.getElementById("size_price_"+j).value == "")
		{
			size_box_flg = 1;
			document.getElementById("size_price_"+j).focus();
		}
	}
	
	if(size_box_flg > 0)
	{
		alert("Please select size of selected item(s)");
		return false;
	}
	
	// Check the Quantity if it zero or not numeric
	var qty_box_flg1 = 0;
	for(k=1; k <= txtbox_cnt1; k++)
	{
		if(document.getElementById("quantity_"+k).value <= 0 || isNaN(document.getElementById("quantity_"+k).value))
		{
			qty_box_flg1 = 1;
			document.getElementById("quantity_"+k).focus();
		}
	}
	
	if(qty_box_flg1 > 0)
	{
		alert("Quantity must be an integer and greater than zero");
		return false;
	}
	 
}


/**************************************************************/



function GetXmlHttpObject()
{
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;
}
