// 4Psite lib
var ps_viewed = new Array();
var ps_name = 'psite_rv';
var ps_days = 30;

function styleImage1(source, target, newId, colorcode, lensecolor, framecolor ) {
 document.getElementById(target).src = source.src;
 document.getElementById('styleImage2').href = source.src;
 id = document.getElementsByName('vwitem')[0];
 url = 'https://order.store.yahoo.net/cgi-bin/wg-order?yhst-11548700755678+' + newId; 
 document.pscart.action = url;
 id.value = newId;
 document.getElementById('pricematch').href = 'http://site.sunglassesline.com/price-match.php?id=' + newId + '&price=' + styleprice;
 document.getElementById('rxglasses').href = 'http://site.sunglassesline.com/select_lenses.php?id=' + newId + '&price=' + styleprice;
 document.getElementById('ps_colorcode').innerHTML = colorcode; 
 document.getElementById('ps_lensecolor').innerHTML = lensecolor;
 document.getElementById('ps_framecolor').innerHTML = framecolor;
}

function styleInit(newId, colorcode, lensecolor, framecolor) {
 id = document.getElementsByName('vwitem')[0];
 url = 'https://order.store.yahoo.net/cgi-bin/wg-order?yhst-11548700755678+' + newId; 
 document.pscart.action = url;
 id.value = newId;
 document.getElementById('pricematch').href = 'http://site.sunglassesline.com/price-match.php?id=' + newId + '&price=' + styleprice;
 document.getElementById('rxglasses').href = 'http://site.sunglassesline.com/select_lenses.php?id=' + newId + '&price=' + styleprice;
 document.getElementById('ps_colorcode').innerHTML = colorcode; 
 document.getElementById('ps_lensecolor').innerHTML = lensecolor;
 document.getElementById('ps_framecolor').innerHTML = framecolor;
}

function styleImage2(target, source) {
 document.getElementById(target).src = source;
}	
	
function createCookie(value) {
	if (ps_days) {
		var date = new Date();
		date.setTime(date.getTime()+(ps_days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = ps_name+"="+value+expires+"; path=/";
}

function readCookie() {
	var nameEQ = ps_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() {
	createCookie(ps_name,"",-1);
}

function cookieToArray () {
	x = readCookie(ps_name);
	if (x != null  ) {
	 ps_viewed = x.split(",");
	 //alert(viewed.length + viewed.toString());
	}
}

function showRV() {
 for (var i=0; i<ps_viewed.length; i++) {
	 temp = new Array();
	 temp = ps_viewed[i].split("|");
	 rv = temp[1];
	 document.write('<div class="psite-rv">' );
	 document.write(rv.link('index.php?main_page=product_info&products_id=' + temp[0]));
	 document.write('<br>' );
	 document.write(temp[2].link('index.php?main_page=product_info&products_id=' + temp[0]));
	 document.write('</div>' );
	 
 }
}

function addRV(value) {
 if (ps_viewed.length > 3 ) ps_viewed.shift();
 skipAdd = true;
 for (var i=0; i<ps_viewed.length; i++) {
   if (value == ps_viewed[i] ) skipAdd = false;	 
 } 
 if (skipAdd == true ) {
  ps_viewed.push(value);
  value1 = ps_viewed.toString();
  createCookie(value1);	
 }
}
	
function popup(mylink, windowname,popw, poph)
{
 if (! window.focus)return true;
 var href;
 var msg;
 if (typeof(mylink) == 'string')
    href=mylink;
 else
    href=mylink.href;
 msg =  'width=' + popw + ',height=' + poph + ',left=50,top=100, location=no, scrollbars=yes';
 window.open(href, windowname, msg);
 return false;
}	
	
function validateQ()  {
	   var message = ('This Field Cannot be Empty:\n\n');	
	   flag = 0;
	   if (document.forms['search'].elements["query"].value == '')  {	
	     message = (message + 'Keywords\n');
		 flag = 1;
	   }
	   if (flag == 1) {	
	     alert(message);
		 return false;
	   } else return true;				
}		


function validate()
{
	var message = ('These Field Cannot be Empty:\n\n');	
	flag = 0;
	
	if (document.forms['price'].elements["name"].value == '')
	{	message = (message + 'Name\n');
			flag = 1;
	}
	
	
	emailStr = document.forms['price'].elements["email"].value
	if ((emailStr.indexOf("@") == -1) || (emailStr.indexOf(".") == -1))
		{
		message = (message + 'Valid email address\n');
			flag = 1;
	}

	if (flag == 1)
	{	alert(message);
		return false;
	}
	else
		return true;				
}		

function eyesunURL1(id) {
  linkid = id;
  link1 = '';
  link2 = '';
  divframe = '<div align="left" style="background-image:url(http://site.sunglassesline.com/images/sunglasses_bar.jpg); width:678px; height:24px; background-repeat:no-repeat;color:#FFFFFF;">';
  ipos = id.search(/sunglasses/i);
  if (ipos > 0 ) {
	  link1 = linkid.toLowerCase();
	  link2 = linkid.replace(/sunglasses/i, "eyeglasses");
	  divhtml1 = '<a href="' + link1 +  '.html"><b>Sunglasses</b></a>';
	  divhtml2 = '<a href="' + link2 + '.html">Eyeglasses</a>';
  }
  ipos = id.search(/eyeglasses/i);
  if (ipos > 0 ) {
	  link2 = id.toLowerCase();
	  link1 = id.replace(/eyeglasses/i, "sunglasses");
	  divhtml1 = '<a href="' + link1 +  '.html">Sunglasses</a>';
	  divhtml2 = '<a href="' + link2 + '.html"><b>Eyeglasses</b></a>';
  }
  if (link1.length > 0 ) {
	  code = '<table style="background-image:url(http://site.sunglassesline.com/images/sunglasses_bar.jpg); width:678px; height:24px; background-repeat:no-repeat;"><tr valign="middle"><td align="center" width="130" class="ps_nav_glass">' + divhtml1 + '</td><td align="center" width="130" class="ps_nav_glass">' + divhtml2 + '</td><td width="418"></td></tr></table>';	  
	  document.getElementById('ps_sun_eye_link').innerHTML = code;
  }
} 

function eyesunURL(id) {
  linkid = id;
  link1 = '';
  link2 = '';
  divframeEYE = '<div align="left" style="background-image:url(images/newdesign/images/cat-eye.jpg); width:700px; height:55px; background-repeat:no-repeat;color:#FFFFFF;">';
  divframeSUN = '<div align="left" style="background-image:url(images/newdesign/images/cat-sun.jpg); width:700px; height:55px; background-repeat:no-repeat;color:#FFFFFF;">';
  ipos = id.search(/sunglasses/i);
  if (ipos > 0 ) { // sun
	  link1 = linkid.toLowerCase();
	  link2 = linkid.replace(/sunglasses/i, "eyeglasses");
	  divFrame = divframeSUN;
	  brand = id.substr(0,ipos-1);
  }
  ipos = id.search(/eyeglasses/i);
  if (ipos > 0 ) {
	  link2 = id.toLowerCase();
	  link1 = id.replace(/eyeglasses/i, "sunglasses");
	  divFrame = divframeEYE;
	  brand = id.substr(0,ipos-1);
  }
  if (link1.length > 0 ) {
	  code = divFrame;
	  code = code + '<table width="790" cellpadding="0" cellspacing="0" border="0"><tr valign="top" height="55" ><td width="133"><a href="' + link1 + '.html"><img src="images/newdesign/images/spacer.gif" border="0" width="133"  height="55" /></a></td><td width="142"><a href="' + link2 + '.html"><img src="images/newdesign/images/spacer.gif" border="0" width="142"  height="55" /></a></td><td width="266"></td><td width="102"><img src="images/newdesign/brands/' + brand + '.gif" /></td><td width="147"></td></tr></table>';
	  code= code + '</div>';	
      document.getElementById('ps_sun_eye_link').innerHTML = code;
  }
} 



function ps_selectColor() {
 formObj = document.getElementById('selectColor');
 newURL = formObj.allcolor.value;
 window.location = newURL;
 //formObj.href=newURL;
 //formObj.submit();
}
	