/*******************************************************************/
/*                                                                 */
/* Copyright (c) 2005-2009 4Psite.com                              */
/*                                                                 */
/*                                                                 */
/*******************************************************************/

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