//
//
x = ((screen.width)/2 -110);
y = 255;
function setVisible(obj)
{
	obj = document.getElementById(obj);
	obj.style.position = "absolute";
	obj.style.top = y;
	obj.style.left = x;
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
}

	function send(link){
	var page_location = location.href;
	page_location = page_location.replace("#top_header", "");
	var details=(page_location+link);
	document.location.href=details;
}


function contact_us(){
	document.frm_print_email.action = "http://www.DDRNation.com/index.php?main_page=contact_us";
	//document.frm_print_email.action = "http://entell4:2000/eyoha/store/index.php?main_page=contact_us";
	document.frm_print_email.email_url.value = self.location;
	document.frm_print_email.submit();
}

function show_filter(){
	document.getElementById('filter_products').style.display = 'inline';
}

function login_logout()
{
	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf("custloggedin");
	if (index1==-1)
	 {
		document.write('Welcome <a href ="https://www.ddrnation.com/index.php?main_page=login" class="greylightsmall" title ="Login">Sign In</a> or <a href="index.php?main_page=create_account" class="greylightsmall" title ="Register with DDRNation.com, its easy.">Register</a> at DDRNation&nbsp;');
	 }
	 else
	 {
		var index2=cookiestring.indexOf("cust_id");
		if(index2==-1)
		 {
				var customer_id ='0';
		 }
		 else
		 {
				var index3 = cookiestring.indexOf(';' , index2);
				if(index3==-1) index3 = cookiestring.length;
				var customer_id = cookiestring.substring(index2+7+1, index3);
				
		 }
		if(customer_id >1){
			var index2=cookiestring.indexOf("cust_name");
			if(index2==-1)
			 {
					var customer_name ='';
			 }
			 else
			 {
					var index3 = cookiestring.indexOf(';' , index2);
					if(index3==-1) index3 = cookiestring.length;
					var customer_name = cookiestring.substring(index2+9+1, index3);
					
			 }
			if(customer_name!=''){
				document.write('<b>Welcome '+customer_name+'  </b>&nbsp;&nbsp; <a href="index.php?main_page=account" class="greylightsmall">My Account</a>&nbsp;&nbsp;<a href="index.php?main_page=logoff" class="greylightsmall">Logout</a>&nbsp;');
			}
		}
		else{
			document.write('Welcome <a href ="https://www.ddrnation.com/index.php?main_page=login" class="greylightsmall" title ="Login">Sign In</a> or <a href="index.php?main_page=create_account" class="greylightsmall" title ="Register with DDRNation.com, its easy.">Register</a> at DDRNation&nbsp;');
		 }
	 }

}

	function shipping_info()
	{
	   window.open("/contents/ShippingInfo.html","shippingInfo", "width=770, height=500,toolbar=0, left=0,top=0, menubar=no, scrollbars=yes, resizable=yes");
	}

	function print_invoice(url)
	{
		window.open(url,"print_inv", "width=800, height=600,toolbar=0, left=0,top=0, menubar=yes, scrollbars=yes, resizable=yes");
	}

	function CreateBookmarkLink(url,title) 
	{
		if (window.sidebar) 
		{ 
			window.sidebar.addPanel(title, url,"");	
		} 
		else if( window.external ) 
		{ 
			window.external.AddFavorite( url, title); 
		}	
		else if(window.opera && window.print) 
		{ 
			return true; 
		} 
	} 

	function Trim(TRIM_VALUE)
	{
		if(TRIM_VALUE.length < 1)
		{
			return"";
		}
		TRIM_VALUE = RTrim(TRIM_VALUE);
		TRIM_VALUE = LTrim(TRIM_VALUE);
		if(TRIM_VALUE=="")
		{
			return "";
		}
		else
		{
			return TRIM_VALUE;
		}
	}

	//////////////////

	function RTrim(VALUE){
		var w_space = String.fromCharCode(32);
		var v_length = VALUE.length;
		var strTemp = "";
		if(v_length < 0)
		{
			return"";
		}
		var iTemp = v_length -1;
		while(iTemp > -1)
		{
			if(VALUE.charAt(iTemp) == w_space)
			{
			}
			else
			{
				strTemp = VALUE.substring(0,iTemp +1);
				break;
			}
			iTemp = iTemp-1;
		}
		return strTemp;
	}

	//////////////////

	function LTrim(VALUE)
	{
		var w_space = String.fromCharCode(32);
		if(v_length < 1)
		{
			return"";
		}
		var v_length = VALUE.length;
		var strTemp = "";
		var iTemp = 0;
		while(iTemp < v_length)
		{
			if(VALUE.charAt(iTemp) == w_space)
			{
				///
			}
			else
			{
				strTemp = VALUE.substring(iTemp,v_length);
				break;
			}
			iTemp = iTemp + 1;
		}
		return strTemp;
	}
	  
	//////////////////

	function check_email(emailaddress)
	{
		var emailStr = emailaddress;
		var checkTLD=1;
		var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
		var emailPat=/^(.+)@(.+)$/;
		var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

		var validChars="\[^\\s" + specialChars + "\]";

		var quotedUser="(\"[^\"]*\")";

		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		var atom=validChars + '+';

		var word="(" + atom + "|" + quotedUser + ")";

		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

		var matchArray=emailStr.match(emailPat);

		if (matchArray==null) 
		{
			alert("Email address seems incorrect (check @ and .'s)");
			return false;
		}
			
		var user=matchArray[1];
		var domain=matchArray[2];

		for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
		alert("The username contains invalid characters.");
		return false;
		   }
		}
		for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
		alert("The domain name contains invalid characters.");
		return false;
		   }
		}

		if (user.match(userPat)==null) {

		alert("The email doesn't seem to be valid.");
		return false;
		}

		var IPArray=domain.match(ipDomainPat);
		if (IPArray!=null) {

		for (var i=1;i<=4;i++) {
		if (IPArray[i]>255) {
		alert("Destination IP address is invalid!");
		return false;
		   }
		}
		return;
		}
				 
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
		alert("The domain name does not seem to be valid.");
		return false;
		   }
		}

		if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
		}

		if (len<2) {
		alert("This address is missing a hostname!");
		return false;
		}
		return true;
	}  
//////////////////////////////

	function setemail()
	{
		if(document.frmsubscribe.email.value=="email address")
		{
			document.frmsubscribe.email.value="";
		}
	}

	function getemail()
	{
		if(document.frmsubscribe.email.value=="email address" || Trim(document.frmsubscribe.email.value)=="")
		{
			document.frmsubscribe.email.value="email address";
		}
	}

	function subscribe()
	{
		if(Trim(document.frmsubscribe.email.value)=="")
		{
			alert("Please enter your email address to receive best deals");
			document.frmsubscribe.email.focus();
			return;
		}
		else if(check_email(Trim(document.frmsubscribe.email.value)))
		{
			document.frmsubscribe.submit();
		}
	}

	///////////////

	function setemail1()
	{
		if(document.frmsubscribe1.email.value=="email address")
		{
			document.frmsubscribe1.email.value="";
		}
	}

	function getemail1()
	{
		if(document.frmsubscribe1.email.value=="email address" || Trim(document.frmsubscribe1.email.value)=="")
		{
			document.frmsubscribe1.email.value="email address";
		}
	}

	function subscribe1()
	{
		if(Trim(document.frmsubscribe1.email.value)=="")
		{
			alert("Please enter your email address to receive best deals");
			document.frmsubscribe1.email.focus();
			return;
		}
		else if(check_email(Trim(document.frmsubscribe1.email.value)))
		{
			document.frmsubscribe1.submit();
		}
	}
//////////////
	function set_menujs_name(section_name)
	{
		var cookiestring ="section_name="+escape(section_name);
		document.cookie=cookiestring;		
	}


	//////////Menu AJAX	bof
    function Call_Ajax(php_url, qry_string, div_name) {
        var httpRequest;
        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/xml');
                // See note below about this line
            }
        } 
        else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } 
                catch (e) {
                           try {
                                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                               } 
                             catch (e) {}
                          }
                                       }

        if (!httpRequest) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }

			//var queryString = "?products_id=" + prodid;
			httpRequest.onreadystatechange = function() { alertContents(httpRequest , div_name); };
			httpRequest.open('GET', php_url + qry_string, true);
			httpRequest.send('');

    }

    function alertContents(httpRequest, div_name) {
        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {

				//alert(httpRequest.responseText);

				document.getElementById(div_name).innerHTML = httpRequest.responseText;
				
            } else {
                alert('There was a problem with the request.');
            }
        }

    }
	//////AJAX EOF

function sortpage()
{
	var curr_url = location.href;
	var cut_url = curr_url.substr(0, curr_url.length-6);
	window.location.href = cut_url+document.filter.disp_order.value+'.html';
}

function check_contact(){
	if(Trim(document.contact_us.contactname.value)=="")
	{
		alert("Please enter your name.");
		document.contact_us.contactname.focus();
		return;
	}
	else if(Trim(document.contact_us.contactemail.value)=="")
	{
		alert("Please enter your email address.");
		document.contact_us.contactemail.focus();
		return;
	}
	else if(check_email(Trim(document.contact_us.contactemail.value)))
	{
		if(document.contact_us.subject.value=="Select Subject"){
			alert("please select subject.");
			document.contact_us.subject.focus();
			return;
		}
		else if(Trim(document.contact_us.enquiry.value)==""){
			alert("please enter your message.");
			document.contact_us.enquiry.focus();
			return;
		}
		else
		{
			document.contact_us.submit();
		}
	}
}

function show_subject(){
	alert(document.contact_us.subject.selectedIndex);
	if(document.contact_us.subject.selectedIndex =="9"){
		document.getElementById('div_subject').style.display = 'inline';
	}
	else{
		document.getElementById('div_subject').style.display = 'none';
	}
}

function text_focus(objElement){
	objElement.className='text_box_focus';
}

function text_blur(objElement){
	objElement.className='text_box_blur';
}


function show_estimator(){
	document.getElementById('shipping_estimator').style.display = 'inline';
}

function hide_estimator(){
	document.getElementById('shipping_estimator').style.display = 'none';
}

function couponpopupWindow(url)
{
   window.open(url,"printWin", "width=770, height=500,toolbar=0, left=0,top=0, menubar=no, scrollbars=yes, resizable=yes"); 
}

function popupWindow(url)
{
   window.open(url,"popWin", "width=770, height=500,toolbar=0, left=0,top=0, menubar=no, scrollbars=yes, resizable=yes"); 
}

function search_focus(objElement){
	if(objElement.value=="Enter Search Keywords"){
		objElement.value ='';
		objElement.className='search_text_box_normal';
	}
	else{
		objElement.className='search_text_box_focus';
	}
}

function search_blur(objElement){
	if(Trim(objElement.value)==""){
		objElement.value="Enter Search Keywords";
	}

	if(Trim(objElement.value)=="Enter Search Keywords"){
		objElement.className='search_text_box_normal';
	}
	else{
		objElement.className='search_text_box_focus';
	}
}

function search_key(objElement){
	objElement.className='search_text_box_focus';
}

function proceed_checkout(){
	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf("custloggedin");
	if (index1==-1)
	 {
		document.location.href = "https://www.ddrnation.com/index.php?main_page=login";
	 }
	 else
	 {
		var index2=cookiestring.indexOf("cust_id");
		if(index2==-1)
		 {
				var customer_id ='0';
		 }
		 else
		 {
				var index3 = cookiestring.indexOf(';' , index2);
				if(index3==-1) index3 = cookiestring.length;
				var customer_id = cookiestring.substring(index2+7+1, index3);
				
		 }
		if(customer_id >=1){
			document.location.href = "https://www.ddrnation.com/index.php?main_page=order_information";
		}
		else{
			document.location.href = "https://www.ddrnation.com/index.php?main_page=login";
		 }
	 }

}