// JavaScript Document

//setTimeout('popWin(110,35,20)',7000);


var allowpop=1;

GB_myShow = function(caption, url, /* optional */ height, width, callback_fn) {
    var options = {
        caption: caption,
        height: height || 420,
        width: width || 630,
        fullscreen: true,
        show_loading: false,
        callback_fn: callback_fn
    }
    var win = new GB_Window(options);
    return win.show(url);
}

// Cookie Definition BEGIN

var expDays = 350; // number of days the cookie should last

//var page = "only-popup-once.html";
//var windowprops = "width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes";

function setTheCookie() {
	var count = GetCookie('count');
	if (count == null) {
		count=1;
		SetCookie('count', count, exp);
	}
}

function checkCount() {
var count = GetCookie('count');
if (count == null) {
//count=1;
//SetCookie('count', count, exp);

//window.open(page, "", windowprops);

//Call the PopWin function
//setTimeout('popWin(110,35,20)',7000);
//End Pop Win Function

//setTimeout('popWin(110,35,20)',7000);

    GB_myShow("Sign Up Here", "http://blog.kingofcopy.com/includes_global/blogpopup.html");
}
//else {
//	count++;

	//GB_myShow("Sign Up Here", "http://www.kingofcopy.com/includes_global/blogpopup.html");
	//GB_show("Sign Up Here", "http://www.kingofcopy.com/includes_global/blogpopup.html", 500, 600);
	//location.href="/products/"
//     }
}


function GetCookie (name) {  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) {    
var j = i + alen;    
if (document.cookie.substring(i, j) == arg)      
return getCookieVal (j);    
i = document.cookie.indexOf(" ", i) + 1;    
if (i == 0) break;   
}  
return null;
}


function SetCookie (name, value) {  
var argv = SetCookie.arguments;  
var argc = SetCookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null;  
var path = (argc > 3) ? argv[3] : null;  
var domain = ".kingofcopy.com"; //  (argc > 4) ? argv[4] : null;  //
var secure = (argc > 5) ? argv[5] : false;  
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) +  
((domain == null) ? "" : ("; domain=" + domain)) +    
((secure == true) ? "; secure" : "");

}


function DeleteCookie (name) {  
var exp = new Date();  
exp.setTime (exp.getTime() - 1);  
var cval = GetCookie (name);  
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt(){
var count = GetCookie('count')
if(count == null) {
SetCookie('count','1')
return 1
}

else {
var newcount = parseInt(count) + 1;
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
   }
}


function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}



// Cookie Definition END



function popWin(){
var ppl="popLayer";
var objppl=findObj(ppl);

if (objppl==null){return;}// if the layer does not exist, do nothing.

var args=arguments,movetoX=parseInt(args[0]),movetoY=parseInt(args[1]),movespeed=parseInt(args[2]);

var cycle=10,pxl="";

if(!document.layers){objppl=objppl.style;}

if(objppl.tmofn!=null){clearTimeout(objppl.tmofn);}

var pplcoordX=parseInt(objppl.left),pplcoordY=parseInt(objppl.top);

var xX=movetoX,yY=movetoY;

	if((pplcoordX!=movetoX)||(pplcoordY!=movetoY)){
	   var moveX=((movetoX-pplcoordX)/movespeed),moveY=((movetoY-pplcoordY)/movespeed);	
	   moveX=(moveX>0)?Math.ceil(moveX):Math.floor(moveX);movetoX=pplcoordX+moveX;	
	   moveY=(moveY>0)?Math.ceil(moveY):Math.floor(moveY);movetoY=pplcoordY+moveY;	
	   if((parseInt(navigator.appVersion)>4||navigator.userAgent.indexOf("MSIE")>-1) && (!window.opera)) {pxl="px";}
	
	   if (moveX!=0){eval("objppl.left='" + movetoX + pxl + "'");}
	
	   if (moveY != 0) {eval("objppl.top = '" + movetoY + pxl + "'");}
	
	   var sFunction = "popWin(" + xX + "," + yY + "," + movespeed+ ")";
	
	   objppl.tmofn = setTimeout(sFunction,cycle);
   	}

}

function findObj(theObj, theDoc){

var p, i, foundObj;

if(!theDoc) theDoc = document;

if((p = theObj.indexOf("?")) > 0 && parent.frames.length)

   {theDoc = parent.frames[theObj.substring(p+1)].document;

    theObj = theObj.substring(0,p);}

if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];

for (i=0; !foundObj && i < theDoc.forms.length; i++)

foundObj = theDoc.forms[i][theObj];

for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)

foundObj = findObj(theObj,theDoc.layers[i].document);

if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

return foundObj;

}

function hideLayer(layername){

layer=findObj(layername);

if(layer.style){layer=layer.style;}

layer.visibility='hidden'; }



// Form Retain



function getCookieRetain(Name){ 
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}

function setCookieRetain(name, value, days){
var expireDate = new Date()
//set "expstring" to either future or past date, to set or delete cookie, respectively
var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days))
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}

function rememberForm(formid){ //Main remember form values object
this.formref=document.getElementById(formid)? document.getElementById(formid) : document.forms[formid]
this.cookiename=formid
this.persistdays=180 //days to persist form values
this.fields=new Array()
this.cookiestr=""
var forminstance=this
rememberForm.dotask(this.formref, function(){forminstance.savevalues()}, "submit") //save form values onsubmit
rememberForm.dotask(window, function(){forminstance.recallvalues()}, "load") //populate form with saved values onload (body)
}

rememberForm.prototype.getfield=function(attr){ //get form field based on its ID or name attribute
var fieldref=document.getElementById(attr)? document.getElementById(attr) : this.formref[attr]
return fieldref
}

rememberForm.prototype.persistfields=function(){ //get form fields to persist values for
for (var i=0; i<arguments.length; i++){
this.fields[i]=this.getfield(arguments[i])
this.fields[i].fname=arguments[i] //store name or id of field in custom property
}
}

rememberForm.prototype.savevalues=function(){ //get form values and store in cookie
for (var i=0; i<this.fields.length; i++){
if (this.fields[i].type=="text")
this.cookiestr+=this.fields[i].fname+":"+escape(this.fields[i].value)+"#"
}
if (typeof this.togglebox!="undefined"){ //if "remember values checkbox" is defined
this.persistdays=(this.togglebox.checked)? this.persistdays : -1 //decide whether to save form values
this.cookiestr=(this.togglebox.checked)? this.cookiestr+"toggleboxid:on;" : this.cookiestr
}
else //if checkbox isn't defined, just remove final "#" from cookie string
this.cookiestr=this.cookiestr.substr(0, this.cookiestr.length-1)+";"
setCookieRetain(this.cookiename, this.cookiestr, this.persistdays)
}

rememberForm.prototype.recallvalues=function(){ //populate form with saved values
var cookievalue=getCookieRetain(this.cookiename)
if (cookievalue!=""){ //parse cookie, where cookie looks like: field1:value1#field2:value2...
var cookievaluepair=cookievalue.split("#")
for (var i=0; i<cookievaluepair.length; i++){
if (cookievaluepair[i].split(":")[0]!="toggleboxid" && this.getfield(cookievaluepair[i].split(":")[0]).type=="text")
this.getfield(cookievaluepair[i].split(":")[0]).value=unescape(cookievaluepair[i].split(":")[1])
else //else if name in name/value pair is "toggleboxid"
this.togglebox.checked=true
}
}
}

rememberForm.prototype.addtoggle=function(attr){
this.togglebox=this.getfield(attr)
}

//Call this function if you wish to clear the user's cookie of any saved values for this form instantly
rememberForm.prototype.clearcookie=function(){
setCookieRetain(this.cookiename, "", -1)
}

rememberForm.dotask=function(target, functionref, tasktype){
var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
if (target.addEventListener)
target.addEventListener(tasktype, functionref, false)
else if (target.attachEvent)
target.attachEvent(tasktype, functionref)
}

