﻿ /// readCookie  ////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//	Will read cookie										//
//////////////////////////////////////////////////////////////

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;
}

/// createCookie  ////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//	Will create cookie										//
//////////////////////////////////////////////////////////////

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=/";
}

/// Query string Handler /////////////////////////////////////
//////////////////////////////////////////////////////////////
// Usage Sample :                                           //
//    var QueryString = new QSObject(window.location.href); //
//    alert(QueryString["sharon"]);                         //
//////////////////////////////////////////////////////////////

function QSObject(querystring){
	var qsReg = new RegExp("[?][^#]*","i");
	hRef = unescape(querystring);
	var qsMatch = hRef.match(qsReg);
	//removes the question mark from the url
	qsMatch = new String(qsMatch);
	qsMatch = qsMatch.substr(1, qsMatch.length -1);
	//split it up
	var rootArr = qsMatch.split("&");
	for(i=0;i<rootArr.length;i++){
	var tempArr = rootArr[i].split("=");
	if(tempArr.length ==2){
	tempArr[0] = unescape(tempArr[0]);
	tempArr[1] = unescape(tempArr[1]);

	this[tempArr[0]]= tempArr[1];
	}
	}
} 

/*** start of rad cms functions ***/

function get_set_DataFromRad(radId, txt)
{
	var radObj = getRadObject(radId);
	// get
	if(typeof(txt)=="undefined")
		return radObj.innerHTML;
	// set
	radObj.innerHTML = txt;
}
function getRadObject(radId)
{
	return document.getElementById("radEditorContainer"+radId);	
}
function get_set_DataFromPH(phId, txt)
{
	var obj = getPhObj(phId);
	if(obj == null)
		return null;
	// get
	if(typeof(txt)=="undefined")
		return (obj.object.html);
	// set
	obj.object.html = txt;
}
function getPhObj(phId)
{
	var phControl = document.getElementById(phId);
	if(phControl == null)
		return null;
	return phControl.getElementsByTagName("object")[0];
}
function openRadWindow(phId, action)
{
	var phText = get_set_DataFromPH(phId);
	if(phText == null)
	{
		alert("You must declare the PlaceHolderClientId property.");
		return;
	}
	var formName = "radForm";
	var formAttributes = 
	"target=myNewWin"+
	"$action="+action+
	"$onsubmit=return createTarget(this.target)" +
	"$method=post";

	var inputsAttributes="";
	inputsAttributes+="phContent="+phText;
	inputsAttributes+="$phId="+phId;
	var myObject = new Object();
    myObject.phContent = phText;
    
    var dlgWidth = 638;
    var dlgLeft = (document.body.clientWidth - dlgWidth)/2;
    var newRadTxt = window.showModalDialog(action, myObject, "dialogWidth:"+dlgWidth+"px; dialogHeight:560px; dialogLeft:"+dlgLeft+"px; dialogTop:50px; help:no; scroll:no; status:no;"); 
	get_set_DataFromPH(phId, newRadTxt);

}
function saveRadContent(radId)
{
	UpdateClicked = true;
	var radTxt = get_set_DataFromRad(radId);
	window.returnValue = radTxt;
	this.close();
}
/*** end of rad cms functions ***/

function attachObjEvent(elementObj, eventName, funcObj)
{
	if(document.all) 
		elementObj.attachEvent(eventName, funcObj);
	else 
		elementObj.addEventListener(eventName.replace("on", ""), funcObj, false)
} 


function getPosition(obj, stopper){
	try {
		var position = {x:0,y:0}; 

		do{
			position.x += obj.offsetLeft;
			position.y += obj.offsetTop;
 			if (obj.tagName.toLowerCase() == "body") break;
			obj = obj.offsetParent;
			if (stopper && obj.id == stopper) break;
		} while(obj)

		return position;
	} catch (e) {
		alert(e.description);
	}
}