// JavaScript Document

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function countdown_clock2(datetouse, year, month, day, hour, minute,id, format){
         //I chose a div as the container for the timer, but
         //it can be an input tag inside a form, or anything
         //who's displayed content can be changed through
         //client-side scripting.
		 var countdownid = id;
         html_code = '<div id="countdown'+id+'"></div>';
         
         document.write(html_code);
         
         countdown2(datetouse, year, month, day, hour, minute, format, countdownid );                
}

function countdown_clock(datetouse, year, month, day, hour, minute,id, format){
         //I chose a div as the container for the timer, but
         //it can be an input tag inside a form, or anything
         //who's displayed content can be changed through
         //client-side scripting.
		 var countdownid = id;
         html_code = '<div id="countdown'+id+'"></div>';
         
         document.write(html_code);
         countdown(datetouse,year, month, day, hour, minute, format, countdownid );                
}
         
function countdown(datetouse,year, month, day, hour, minute, format, countdownid2){
         Today = new Date(datetouse);
         Todays_Year = Today.getFullYear() - 2000;
         Todays_Month = Today.getMonth();                  
		 var towrite = '';
         
         //Convert both today's date and the target date into miliseconds.                           
         Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), 
                                 Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();
		 
         Target_Date = (new Date(year, month - 1, day, hour, minute, 00)).getTime();                  
         
         //Find their difference, and convert that into seconds.                  
         Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
         
         if(Time_Left < 0)
            Time_Left = 0;
         
         switch(format)
               {
               case 0:
                    //The simplest way to display the time left.
                    towrite = Time_Left + ' seconds';
                    break;
               case 1:
                    //More datailed.
                    days = Math.floor(Time_Left / (60 * 60 * 24));
                    Time_Left %= (60 * 60 * 24);
                    hours = Math.floor(Time_Left / (60 * 60));
                    Time_Left %= (60 * 60);
                    minutes = Math.floor(Time_Left / 60);
                    Time_Left %= 60;
                    seconds = Time_Left;
                    
                    dps = 's'; hps = 's'; mps = 's'; sps = 's';
                    if(days == 1) dps ='';
                    if(hours == 1) hps ='';
                    if(minutes == 1) mps ='';
                    if(seconds == 1) sps ='';
                    
					if( days != 0 ){
						towrite = '<table cellspacing="0" cellpadding="0" border="0" style="position: relative; top: 12px; left: 0px;"><tr><td><div style="width: 0px;"><div align="center"><b>'; 

					} else { 
						towrite = '<table cellspacing="0" cellpadding="0" border="0" style="position: relative; top: 12px; left: 0px;"><tr><td><div style="width: 0px;"><div align="center"><b>';
					}
					
                    if( days == 0 && hours == 0 ){ 
						towrite += '</b></div></div></td><td><div style="width: 27px;"><div align="center"><b>0'; 
					} else {
							towrite += '</b></div></div></td><td><div style="width: 27px;"><div align="center"><b>' + hours;
					}
					
					if( days == 0 && hours == 0 && minutes == 0 ){
	                    towrite += '</b></div></div></td><td><div style="width: 29px;"><div align="center"><b>0'; 
					} else {
						towrite +=  '</b></div></div></td><td><div style="width: 29px;"><div align="center"><b>' + minutes;
					}
					
					towrite += '</b></div></div></td><td><div style="width: 30px;"><div align="center"><b>' + seconds;
					towrite += '</b></div></div></td><td><div style="font: 10pt Arial, Helvetica, sans-serif; width: 97px; padding-left: 5px;"></div></td></tr></table>';
                    
					if( days == 0 && hours == 0 && minutes == 0 && seconds == 0 ) window.location.reload();
					
					break;
               default: 
                    towrite = Time_Left + ' seconds';
               }
               
			   document.getElementById("countdown"+countdownid2).innerHTML = towrite;
		Today.setSeconds(Today.getSeconds()+1);
         //Recursive call, keeps the clock ticking.
         setTimeout('countdown("'+ Today+'",' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ',' + countdownid2 + ');', 1000);
		 
         }
		 
function countdown2(datetouse, year, month, day, hour, minute, format, countdownid2){
         Today = new Date(datetouse);
         Todays_Year = Today.getFullYear() - 2000;
         Todays_Month = Today.getMonth();                  
		 var towrite = '';
         
         //Convert both today's date and the target date into miliseconds.                           
         Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), 
                                 Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();                                 
         Target_Date = (new Date(year, month - 1, day, hour, minute, 00)).getTime();                  
         
         //Find their difference, and convert that into seconds.                  
         Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
         
         if(Time_Left < 0)
            Time_Left = 0;
         
         switch(format)
               {
               case 0:
                    //The simplest way to display the time left.
                    towrite = Time_Left + ' seconds';
                    break;
               case 1:
                    //More datailed.
                    days = Math.floor(Time_Left / (60 * 60 * 24));
                    Time_Left %= (60 * 60 * 24);
                    hours = Math.floor(Time_Left / (60 * 60));
                    Time_Left %= (60 * 60);
                    minutes = Math.floor(Time_Left / 60);
                    Time_Left %= 60;
                    seconds = Time_Left;
                    
                    dps = 's'; hps = 's'; mps = 's'; sps = 's';
                    if(days == 1) dps ='';
                    if(hours == 1) hps ='';
                    if(minutes == 1) mps ='';
                    if(seconds == 1) sps ='';
                    
					towrite = '<table cellspacing="0" cellpadding="0" border="0"><tr><td style="padding-top: 7px; border: 0px; width: 32px; text-align: center" class="size8"><b>';
					
                    if( days == 0 && hours == 0 ){ 
						towrite += '0</b></td><td style="padding-top: 7px; border: 0px;width: 32px; text-align: center" class="size8"><b>'; 
						
					} else {
							towrite += hours +'</b></td><td style="padding-top: 7px; border: 0px;width: 32px; text-align: center" class="size8"><b>';
					}
					
					if( days == 0 && hours == 0 && minutes == 0 ){
	                    towrite += '0</b></td><td style="padding-top: 7px; border: 0px;width: 32px; text-align: center;" class="size8"><b>'; 
					} else {
						towrite +=  minutes + '</b></td><td style="padding-top: 7px; border: 0px;width: 32px; text-align: center;" class="size8"><b>';
					}
					
					towrite += seconds;
					towrite += '</b></td></tr></table>';
                    
					if( days == 0 && hours == 0 && minutes == 0 && seconds == 0 ) window.location.reload();
					
					break;
               default: 
                    towrite = Time_Left + ' seconds';
               }
               
			   document.getElementById("countdown"+countdownid2).innerHTML = towrite;

         Today.setSeconds(Today.getSeconds()+1);
         //Recursive call, keeps the clock ticking.
         setTimeout('countdown2("'+ Today+'",' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ',' + countdownid2 + ');', 1000);
		 
         }

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function createRequestObject(){
	var request_o; 
	var browser = navigator.appName; 
			
	if(browser == "Microsoft Internet Explorer"){
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		request_o = new XMLHttpRequest();
	}
	return request_o; 
}

function hilitemoreitem(obj){
	obj.style.backgroundColor = "#06F";
	obj.style.color = "#fff";
}

function normalmoreitem(obj){
	obj.style.backgroundColor = "#E6DFFF";
	obj.style.color = "#000";
}

function addlayaway(productid, bbandsize, bandsize, price ){
	createCookie("productid", productid, 1);
	if( bbandsize )	createCookie("bandsize", bandsize, 1);
	createCookie("price", price, 1 );
	document.addlayaway.submit();
}

function showmoredropdown(obj, obj2){
	document.getElementById(obj).style.visibility = "visible";
	document.getElementById(obj2).src=imageMoreOn.src;
}

function hidemoredropdown(obj, obj2){
	document.getElementById(obj).style.visibility = "hidden";
	document.getElementById(obj2).src=imageMore.src;
}

function display_main_content(page_content){
	hide_main_content();
	load_main_content(page_content);
}

function show_main_content(){
	$(document).ready(function(){
		$("#main-content").slideDown("normal");
	});
}

function hide_main_content(){
	$(document).ready(function(){
		$("#main-content").slideUp("fast");
	});
}

function show_display_container(objname){
	$(document).ready(function(){
		$("#"+objname).slideDown("normal");
	});
}

function display_slide_container(objname,ajaxpage,productid, price){
	
	var sInclude = "/inc/ajaxslide.inc.php?sec="+ajaxpage+"&productid="+productid+"&price="+price;
	
	$(document).ready(function(){
		$("#"+objname).slideUp("fast");
    	$("#"+objname+" .content").load(sInclude, show_display_container(objname));
	});
}

function display_slide_close(objname){
	$("#"+objname).slideUp("fast");	
}

function load_main_content(page_content){
	$(document).ready(function(){
    	$("#main-content").load("/inc/main-content.php", "section="+page_content, show_main_content());
	});
}

function goPage(page){
	document.location='/'+page;
}

function goProdCat(id){
	document.location='/products.php?catid='+id;
}

function goProdGift(id){
	document.location='/products.php?gift='+id;
}

var http = createRequestObject();

function checkemail(formvalue){
	var result
	var str= formvalue
	var filter=/^.+@.+\..{2,3}$/

	if (filter.test(str))
		result=true
	else {
		alert("Please input a valid email address!")
		result=false
	}
	
	return (result)
}

function handleContactForm(){
	if(http.readyState == 4){
		var response = http.responseText;
		document.getElementById("contactform_container").innerHTML = response;
	}
}

function handleFindWatchForm(){
	if(http.readyState == 4){
		var response = http.responseText;
		document.getElementById("cantfindform_container").innerHTML = response;
	}
}

function ajaxSendContactForm(name,email,comments, phone, category){
	var url = location.protocol+'//'+location.hostname+':'+location.port+'/ajax/contactform.ajax.php?name='+name+'&email='+email+'&comments='+comments+'&phone='+phone+'&category='+category;
	http.open('get',url);
	http.onreadystatechange = handleContactForm;
	http.send(null);
}


function ajaxSendFindWatchForm(fullname,email,phone, watchgender,condition,watchstyle,watchmaterial,otherdetails){
	var url = location.protocol+'//'+location.hostname+':'+location.port+'/ajax/findwatch.ajax.php?fullname='+fullname+'&email='+email+'&phone='+phone+'&watchgender='+watchgender+'&condition='+condition+'&watchstyle='+watchstyle+'&watchmaterial='+watchmaterial+'&otherdetails='+otherdetails;
	http.open('get',url);
	http.onreadystatechange = handleFindWatchForm;
	http.send(null);
}

function handleReturnForm(){
	if(http.readyState == 4){
		var response = http.responseText;
		document.getElementById("returnform_container").innerHTML = response;
	}
}

function ajaxSendReturnForm(name,email,comments, phone, ordernumber){
	var url = location.protocol+'//'+location.hostname+':'+location.port+'/ajax/returns.ajax.php?name='+name+'&email='+email+'&comments='+comments+'&phone='+phone+'&ordernumber='+ordernumber;
	http.open('get',url);
	http.onreadystatechange = handleReturnForm;
	http.send(null);
}

function displayCurrentDate(){
	var months=new Array(13);
	
	months[1]="January";
	months[2]="February";
	months[3]="March";
	months[4]="April";
	months[5]="May";
	months[6]="June";
	months[7]="July";
	months[8]="August";
	months[9]="September";
	months[10]="October";
	months[11]="November";
	months[12]="December";
	
	var time=new Date();
	var lmonth=months[time.getMonth() + 1];
	var date=time.getDate();
	var year=time.getYear();
	
	if (year < 2000)
		year = year + 1900;

	document.write("<b>" + lmonth + " ");
	document.write(date + ", " + year + "</b>");
}

function menuon(obj){
	obj.style.borderBottom = "1px solid #666666";
	obj.style.borderTop = "1px solid #CCCCCC";
	obj.style.borderLeft = "1px solid #CCCCCC";
	obj.style.borderRight = "1px solid #666666";
}

function showCSSubmenu(){
	obj = document.getElementById("submenu_customerservice");
	obj.style.visibility="visible";
}

function hideCSSubmenu(){
	obj = document.getElementById("submenu_customerservice");
	obj.style.visibility="hidden";
}

function showContactSubmenu(){
	obj = document.getElementById("submenu_contact");
	obj.style.visibility="visible";
}

function hideContactSubmenu(){
	obj = document.getElementById("submenu_contact");
	obj.style.visibility="hidden";
}

function showJewelrySubmenu(){
	obj = document.getElementById("submenu_jewelry");
	obj.style.visibility="visible";
}

function hideSubmenu(name){
	obj = document.getElementById("submenu_"+name);
	obj.style.visibility="hidden";
}

function showSubmenu(name){
	obj = document.getElementById("submenu_"+name);
	obj.style.visibility="visible";
}

function hideJewelrySubmenu(){
	obj = document.getElementById("submenu_jewelry");
	obj.style.visibility="hidden";
}

function showTimepiecesSubmenu(){
	obj = document.getElementById("submenu_timepieces");
	obj.style.visibility="visible";
}

function hideTimepiecesSubmenu(){
	obj = document.getElementById("submenu_timepieces");
	obj.style.visibility="hidden";
}

function showProductSubmenu(){
	obj = document.getElementById("submenu_collection");
	obj.style.visibility="visible";
}

function hideProductSubmenu(){
	obj = document.getElementById("submenu_collection");
	obj.style.visibility="hidden";
}

function showSubSubmenu(idname){
	obj = document.getElementById(idname);
	obj.style.visibility="visible";
}

function hideSubSubmenu(idname){
	obj = document.getElementById(idname);
	obj.style.visibility="hidden";
}

function unhilitesubmenu(obj){
	obj.style.background = "#6d84e8";
	obj.style.color = "white";
}

function hilitesubmenu(obj){
	obj.style.background = "#1a3496";
	obj.style.color = "white";
}

function menuoff(obj){
	obj.style.borderBottom = "1px solid #CCCCCC";
	obj.style.borderTop = "1px solid #666666";
	obj.style.borderLeft = "1px solid #666666";
	obj.style.borderRight = "1px solid #CCCCCC";
}

function checkfriendform(){
	var sendname = document.getElementById("sendname").value;
	var sendemail = document.getElementById("sendemail").value;
	var friendname = document.getElementById("friendname").value;
	var friendemail = document.getElementById("friendemail").value;
	var message = document.getElementById("message").value;
	var product = document.getElementById("product").value;
		
	var send = true;
	if( sendname == "" ){
		alert ("Please enter your name");
		send = false;
	}
	
	if( friendname == "" ){
		alert ("Please enter your friend's name");
		send = false;
	}
	
	checkemail( sendemail ) ? send = true : send = false;
	checkemail( friendemail ) ? send = true : send = false;
	if( send ){
		ajaxSendTellAFriendForm(sendname,sendemail,friendname, friendemail,message,product);
	}
	
}

function handleTellAFriendForm(){
	if(http.readyState == 4){
		var response = http.responseText;
		document.getElementById("tellafriend_container").innerHTML = response;
	}
}

function ajaxSendTellAFriendForm(sendname,sendemail,friendname, friendemail,message,product){
	var url = location.protocol+'//'+location.hostname+':'+location.port+'/ajax/tellafriend.ajax.php?sendname='+sendname+'&sendemail='+sendemail+'&friendname='+friendname+'&friendemail='+friendemail+'&message='+message+'&product='+product;
	http.open('get',url);
	http.onreadystatechange = handleTellAFriendForm;
	http.send(null);
}