/*******************************************************************/
/*                                                                 */
/* Copyright (c) 2005-2010 4Psite.com                              */
/*                                                                 */
/*                                                                 */
/*******************************************************************/
var ps_viewed = new Array();
var ps_name = 'psite_rv';
var ps_days = 30;

var cname = 'ps_log';
var sp_images = new Array();
function getForm(jsonData) {
 var core = jsonData[0]['html'];
 if (core == '1') {
	createCookie(cname,'1',30);
	document.getElementById('ps_login').innerHTML = '<a href="#" onClick="logout();"><img src="http://site.vistageknowledgecenter.com/images/nav/top_Sign_Out.jpg"  border=0"></a>';
	window.location = 'index.html';
  } else {
	eraseCookie(cname);
	document.getElementById('login_msg').innerHTML = '<span class="ps_error_msg">incorrect user ID or password</span>';
	document.getElementById('ps_login').innerHTML = '<a href="login.html" ><img src="http://images.vistageknowledgecenter.com/new/top_memberLogin.jpg" border="0"></a>';
 }
} 

function validate(form) {
 id = form.ID.value;
 //pass = form.password.value;
 param = '&id=' + id; // + '`' + pass;
 var req  = 'http://site.vistageknowledgecenter.com/4psite/access.php?callback=getForm' + param;
 bObj = new JSONscriptRequest(req); 
 bObj.buildScriptTag(); 
 bObj.addScriptTag();
 return false;
}

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 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 islogged() {
 rc = readCookie(cname);
 if (rc) {
	document.getElementById('ps_login').innerHTML = '<a href="#" onClick="logout();"><img src="http://site.vistageknowledgecenter.com/images/nav/top_Sign_Out.jpg"  border=0"></a>'; 
 } else {
	 document.getElementById('ps_login').innerHTML = '<a href="login.html" ><img src="http://images.vistageknowledgecenter.com/new/top_memberLogin.jpg" border="0"></a>';
 }
	
}

function logout() {
	eraseCookie(cname);
	window.location = 'index.html';	
}

function psiteDiscount() {
 	rc = readCookie(cname);
	if (rc != null ) {
		obj = document.getElementById('ps_member_in');
		obj.setAttribute("value", ps_mem_disc);
	}	
}

function psiteMemberPrice(price, sprice) {
 mprice = (eval (price +  psiteExtractPrice(ps_mem_disc)));
 mprice = mprice.toFixed(2);
 document.getElementById('ps_mem_price_cont').innerHTML = '<span class="sale-price-bold">$' + mprice + '</span>';
}

function psiteExtractPrice(str) {
 price = 0;
 str.replace(/$/,""); 
 i1 = str.lastIndexOf("(");
 if (i1 > -1 ) {
   i2 = str.lastIndexOf(")");
   if (i2 > -1 ) price = str.substr(i1+1,i2-i1- 1);  
 }
 return (price);
}

function getRating(id) {
  var param = '&id=' + id;
  var req  = 'http://site.vistageknowledgecenter.com/4psite/getrate.php?callback=getRate' + param;
  bObjr = new JSONscriptRequest(req); 
  bObjr.buildScriptTag(); 
  bObjr.addScriptTag();
  return false;
}

function getRate(jsonData) {
 var core = jsonData[0]['html'];
 //alert(core);
 //var firstRating = new Spry.Widget.Rating(\"static\", {ratingValueElement: 'readOnly', readOnly: true});
 var rate = new Spry.Widget.Rating("static", {ratingValue:core, readOnly:true} );
 if (jsonData[0]['data'] != null) {
  document.getElementById('ps_rate_sum').innerHTML = jsonData[0]['head'];
  document.getElementById('ps_rateview').innerHTML = '<a href="#" onclick="TabbedPanels1.showPanel(5)">' + jsonData[0]['review'] + '</a>';
  //if (jsonData[0]['data'] != null)
  document.getElementById('ps_rating').innerHTML = jsonData[0]['data'];
 }
} 

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;
}

/*
"<a href='#'  onclick=\"return popup('http://site.vistageknowledgecenter.com/4psite/stars-popup.php?id="
									 
"','star','500','400')\" >Rate this product</a>"
*/

function slide(){
 var className = 'SlidingPanelsContent'; //change the className that is on all your content panels..
 var panelCount = sp1.getContentPanelsCount();//get panel length
 var current = sp1.getCurrentPanel(); //get current panel
 var group = sp1.getContentGroup(); //get our group
 var panelNumber = 0;
 if(group.hasChildNodes()){
  var j = 0;
  for(var i = 0, l = group.childNodes.length; i < l; i ++){
   if(group.childNodes[i].className && group.childNodes[i].className.search(new RegExp("\\b" + className + "\\b")) != -1){ // if it has SlidingPanelsContent class we found the correct node.
     if(group.childNodes[i] == current) // if it matches our current panel, we have a number
        panelNumber = j;
     j++; //increase our panelcounter
   }
   
  }
 }
 linkx = sp_images[panelNumber];
 //alert(panelx);
 popw = 600;
 poph = 700;
 popup(linkx, 'imagex',popw, poph);
 //alert();
} 

function ps_validate()
{
	var message = ('These Field Cannot be Empty:\n\n');	
	flag = 0;
	
	emailStr = document.forms['NewsletterSignup'].elements["email_news"].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;				
}	

//r view
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 = '<img src="' + temp[1] + '" alt="' + temp[2] + '" border="0" width="150" >'
	 document.write('<div class="psite-rv">' );
	 document.write(rv.link(temp[0] + '.html'));
	 document.write('<br>' );
	 document.write(temp[2].link(temp[0] + '.html'));
	 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 p_flash(nav) {
 if (nav == 5 ) {
   window.location = flash_refx;
  } else {
   document.getElementById('flash').src = flash_img[nav];
   flash_refx = flash_ref[nav];
  } 
}