// JavaScript Document



siteUrl = "http://www.montecarlocollections.com";




function checkStock(){



var length = document.cart.stock.length;


if(length){
	//alert(document.cart.quantity[0].value);
//alert(document.cart.stock[0].value);
		for(i=0;i<length;i++){
		
					if((parseInt(document.cart.quantity[i].value) > parseInt(document.cart.stock[i].value))||(parseInt(document.cart.quantity[i].value) < 0))
					{
					/*alert("Quantity can not exceed available stock of "+document.cart.stock[i].value+ " for Product Code " +document.cart.proId1[i].value + " of size "+document.cart.sizes[i].value);*/
					
					if(parseInt(document.cart.quantity[i].value) < 0)
{
	alert("Sorry, Your Quantity must not be in negative number");
}
else
{
	
					alert("Sorry, Your Quantity is more then stock available");
}
					document.cart.quantity[i].focus;
					return false;
					}
		}
}
else if((parseInt(document.cart.quantity.value) > parseInt(document.cart.stock.value))||(parseInt(document.cart.quantity.value) < 0))	{

/*alert("Quantity can not exceed available stock of "+document.cart.stock.value+ " for Product Code " +document.cart.proId1.value + " of size "+document.cart.sizes.value);*/
if(parseInt(document.cart.quantity.value) < 0)
{
	alert("Sorry, Your Quantity must not be in negative number");
}
else
{
alert("Sorry, Your Quantity is more then stock available");
}
document.cart.quantity.focus;
return false;
	
}

document.cart.submit();
}


function changeMode(mode)

{

		//alert(f1);

	//if(document.cart.country.value==''){

		//alert("Please select country to proceed..");

		//return false;

		//}	

	document.cart.mode.value = "performAction";

	document.cart.process.value = "Checkout";

	document.cart.submit();

}

function changeMode1(mode)

{

		

	if(mode=='continue')	

	document.cart.mode.value = "continue";

	else

	document.cart.mode.value = "performAction";

	

	document.cart.submit();

}



function editDeleteDeliveryAddress(mod,pro,id)

{

	var form = document.forms[1];

	

	

	form.process.value = pro;

	form.mode.value = mod;

	

	form.id.value = id;



	form.submit();





}



var xmlHttp



function stateChanged() 

{ 



}

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;

}

function changeModeToOrder(f1){

	

	f1.mode.value = "placeOrder";

		

			

	

}





function showNextPage(path, extraParams){



	var redirectURL = path + extraParams + "page=" + document.getElementById('pageSelect').value;

	

	window.location.href = redirectURL;

}





function showUser1(str,w)

{ 


if(document.cart.country.value!="India")
{
	alert("Shipping Charges Extra for outside India, Please contact us.");
	document.getElementById('MyBox1').className='hide';

}
else
{
	document.getElementById('MyBox1').className='show';

}



var total=parseInt(document.cart.totalprice.value);



xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)

 {

 alert ("Browser does not support HTTP Request")

 return

 } 

var url= siteUrl + "/classes/getweight.php"

url=url+"?country="+str

url=url+"&weight="+w

url=url+"&total="+total



xmlHttp.onreadystatechange=stateChanged2 

xmlHttp.open("GET",url,true)

xmlHttp.send(null)

}



function stateChanged2() 

{ 

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

 { 

 //alert(document.cart.totalprice.value);

 //alert(document.getElementById("grandTotal").innerHTML);

 document.getElementById("grandTotal").innerHTML=xmlHttp.responseText 

 } 

}





// pop ups





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

//@Author: Adrian "yEnS" Mato Gondelle

//@website: www.yensdesign.com

//@email: yensamg@gmail.com

//@license: Feel free to use it, but keep this credits please!					

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



//SETTING UP OUR POPUP

//0 means disabled; 1 means enabled;



var popupStatus = 0;



//loading popup with jQuery magic!

function loadPopup(){

	//loads popup only if it is disabled

	if(popupStatus==0){

		$("#backgroundPopup").css({

			"opacity": "0.7"

		});

		$("#backgroundPopup").fadeIn("slow");

		$("#popupContact").fadeIn("slow");

		popupStatus = 1;

		

	}

	

}



//disabling popup with jQuery magic!

function disablePopup(){

	

	//disables popup only if it is enabled

	if(popupStatus==1){

		$("#backgroundPopup").fadeOut("slow");

		$("#popupContact").fadeOut("slow");

		popupStatus = 0;

	}

}



//centering popup

function centerPopup(){

	//request data for centering

	if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {

    //IE 6+ in 'standards compliant mode'

    var windowWidth = document.documentElement.clientWidth;

    	var windowHeight = document.documentElement.clientHeight;

  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {

    //IE 4 compatible

      var windowWidth  = document.body.clientWidth;

    var windowHeight = document.body.clientHeight;

  }



	

	

	//var windowWidth = document.documentElement.clientWidth;

	//alert(windowWidth);

	//var windowHeight = document.documentElement.clientHeight;

	//var windowHeight = 566;

	//var windowWidth = 1003;

	

	var popupHeight = $("#popupContact").height();

	var popupWidth = $("#popupContact").width();

	//centering

	$("#popupContact").css({

		"position": "absolute",

		//"top": windowHeight/2-popupHeight/2,

		//"left": windowWidth/2-popupWidth/2

		"top": windowHeight/2-popupHeight/2,

		"left": windowWidth/2-popupWidth/2

	});

	//only need force for IE6

	

	$("#backgroundPopup").css({

		"height": windowHeight

	});

	

}





//CONTROLLING EVENTS IN jQuery





function confirmRequest1(url,width1,height1,id){

	

	var id1 = "#"+id;

	

	$("#Express").click(function(){

		//centering with css

		centerPopup();

		//load popup

		loadPopup();

	});

	

		document.getElementById("cframe1").src=url

}







var oXHR = null;

siteUrl = "http://www.montecarlocollections.com";





function sendRequest(f,mode){

alert(f);

mode= typeof(mode) != 'undefined' ? mode : '';



var oForm = f ;



if(typeof(f)=="object"){

var sBody = getRequestBody(f);

var script = oForm.action;

}

else

var script = f;





if(!oXHR){



var oXHR = createXHR();



} 





document.getElementById("list").innerHTML = '<center><p><p><img src="'+siteUrl+'/images/loading1.gif" width="100" height="100" /></center>';



oXHR.open("post",script,true);





oXHR.setRequestHeader("Content-Type","application/x-www-form-urlencoded");



oXHR.onreadystatechange = function(){

									

	

									if(oXHR.readyState == 4){

											//alert(oXHR.status)

											//alert(oXHR.responseText)

											if(oXHR.status == 200){

												

												alert(oXHR.responseText)

													if(mode=='protectPhoto' || mode=='changePicture'){

													//alert(oXHR.responseText)

													document.getElementById("status").innerHTML = oXHR.responseText;

													

													}

											

												 else

												 document.getElementById("list").innerHTML = oXHR.responseText;

												 

											}else{

												if(mode == 'search'){

										document.getElementById("list").innerHTML = "An error has ocurred: "+ oXHR.tatusText;

												document.searchForm.searchValue.focus();

												}

												

												else

												 document.getElementById("list").innerHTML = "An error has ocurred: "+ oXHR.tatusText;

											}

									

									}



							};

							

	oXHR.send(sBody);	

}







function encodeNameAndValue(sName, sValue){



var sParam = encodeURIComponent(sName);



sParam += "=";



sParam += encodeURIComponent(sValue);

return sParam;

}



function createXHR(){



	if(typeof XMLHttpRequest != "undefined"){

	

		return new XMLHttpRequest();

	}

	else if(window.ActiveXObject){



			var aVersions = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.3.0"];



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

		

					try{

					   var oXHR = new ActiveXObject(aVersions[i]);

					   return oXHR;

					}catch(oError){}

			

	

	

			}

	}

}



function getRequestBody(f){



	var aParams = new Array();

	var oForm = f;

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

	

		var oField = oForm.elements[i];

		

			switch(oField.type){

			

				case "button":

				case "submit":

				case "reset":

						break;

						

				case "checkbox":		

				case "radio":

						if(!oField.checked){

						break;

						}

				case "text":

				case "select-one":

				case "textarea":

				case "hidden":

				case "password":	

						aParams.push(encodeNameAndValue(oField.name, oField.value));

						break;

						

				default:

							

			

			

			}

	}

	

	return aParams.join("&");



}

var dragapproved=false

var minrestore=0

var initialwidth,initialheight

var ie5=document.all&&document.getElementById

var ns6=document.getElementById&&!document.all



function iecompattest(){

return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body

}



function drag_drop(e){

if (ie5&&dragapproved&&event.button==1){

document.getElementById("dwindow").style.left=tempx+event.clientX-offsetx+"px"

document.getElementById("dwindow").style.top=tempy+event.clientY-offsety+"px"

}

else if (ns6&&dragapproved){

document.getElementById("dwindow").style.left=tempx+e.clientX-offsetx+"px"

document.getElementById("dwindow").style.top=tempy+e.clientY-offsety+"px"

}

}



function initializedrag(e){

offsetx=ie5? event.clientX : e.clientX

offsety=ie5? event.clientY : e.clientY

document.getElementById("dwindowcontent").style.display="none" //extra

tempx=parseInt(document.getElementById("dwindow").style.left)

tempy=parseInt(document.getElementById("dwindow").style.top)



dragapproved=true

document.getElementById("dwindow").onmousemove=drag_drop

}



function loadwindow(url,width,height){

	

if (!ie5&&!ns6)

window.open(url,"","width=width,height=height,scrollbars=1")

else{

document.getElementById("dwindow").style.display=''

document.getElementById("dwindow").style.width=initialwidth=width+"px"

document.getElementById("dwindow").style.height=initialheight=height+"px"

document.getElementById("dwindow").style.left="30px"

document.getElementById("dwindow").style.top=ns6? window.pageYOffset*1+30+"px" : iecompattest().scrollTop*1+30+"px"

document.getElementById("cframe").src=url

}

}



function maximize(){

if (minrestore==0){

minrestore=1 //maximize window

document.getElementById("maxname").setAttribute("src",siteUrl+"/images/restore.gif")

document.getElementById("dwindow").style.width=ns6? window.innerWidth-20+"px" : iecompattest().clientWidth+"px"

document.getElementById("dwindow").style.height=ns6? window.innerHeight-20+"px" : iecompattest().clientHeight+"px"

}

else{

minrestore=0 //restore window

document.getElementById("maxname").setAttribute("src",siteUrl+"/images/max.gif")

document.getElementById("dwindow").style.width=initialwidth

document.getElementById("dwindow").style.height=initialheight

}

document.getElementById("dwindow").style.left=ns6? window.pageXOffset+"px" : iecompattest().scrollLeft+"px"

document.getElementById("dwindow").style.top=ns6? window.pageYOffset+"px" : iecompattest().scrollTop+"px"

}



function closeit(){

document.getElementById("dwindow").style.display="none"

}



function stopdrag(){

dragapproved=false;

document.getElementById("dwindow").onmousemove=null;

document.getElementById("dwindowcontent").style.display="" //extra

}







function confirmRequest(f,w,h){

	

	if(confirm("Do you realy want to process the request?"))	{

	loadwindow(f,w,h);

		

	}

}





var xmlHttp

function checkEmailAvailable(email)

{ 



xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)

 {

 alert ("Browser does not support HTTP Request")

 return

 } 

var url=siteUrl+"/checkEmail.php"

url=url+"?email="+email



document.getElementById("username").innerHTML = '<img src="'+siteUrl+'/images/loading.gif"  />';



xmlHttp.onreadystatechange=stateChanged 

xmlHttp.open("GET",url,true)

xmlHttp.send(null)

}



function stateChanged() 

{ 

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

 { 

 

		if(xmlHttp.responseText!="1" && xmlHttp.responseText!=true){

		document.registerMember.email.value='';

		 document.getElementById("username").innerHTML = xmlHttp.responseText;

		 } 

		 else 

		 document.getElementById("username").innerHTML = "<img src='"+siteUrl+"/images/admin/tick.png' align='absmiddle'> Email available.";

}

}

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;

}

