function popitup(url) {
   	w = screen.availWidth;
   	h = screen.availHeight;

	var popW = 500, popH = 500;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

	newwindow=window.open(url,'name','height=500,width=500,scrollbars=no,menubar=no,top='+topPos+',left='+leftPos);
	if (window.focus) {newwindow.focus()}
	return false;
}

function re(cels) {
	document.location.href=cels;	
}

function chkStars(obj){
	val = obj.options[obj.selectedIndex].value;
	t = val.split(":");
	if(t[2] == 1){
		show('trstars');
	} else {
		hide('trstars');
	}
}

function chkStarsEdit(){
	val = document.getElementById('cat').options[document.getElementById('cat').selectedIndex].value;
	t = val.split(":");
	
	if(document.getElementById('cat2')){
		val2 = document.getElementById('cat2').options[document.getElementById('cat2').selectedIndex].value;
		t2 = val2.split(":");
		if((t[2] == 1) || (t2[2] == 1)){
			show('trstars');
		} else {
			hide('trstars');
		}
	} else {
		if(t[2] == 1){
			show('trstars');
		} else {
			hide('trstars');
		}
	}
}

function changeCountry(i){
	val = '/?cn='+i.options[i.selectedIndex].value;
	re(val);
}

function openLife(obj, sk){
	hs.htmlExpand(obj,{contentId:'hspop2',maincontentId:'r'+sk+'content',width:240,targetX:'r'+sk+' 360px',targetY:'r'+sk+' -50px',dimmingOpacity:0});	
}

function stripHtml(str){
	var reTag = /<(?:.|\s)*?>/g;
	return str.replace(reTag, "");
}

/*function addFav(){
	if(document.all) window.external.AddFavorite('http://www.cornerstonesworld.com','Cornerstones World');
	else if(window.sidebar)window.sidebar.addPanel('Cornerstones World','http://www.cornerstonesworld.com','');	
}
*/
function listClick (e) {
    var obj = (e.target) ? e.target : e.srcElement;
    if (obj.type == 'checkbox')
    	return false;
	else return true;
}


function chSelect(sel)
{
	var arrInput = document.getElementsByTagName("input")
	for (i = 0; i < arrInput.length; i++) {
		if ((arrInput[i].type == "checkbox") && (arrInput[i].disabled == false)) {
			arrInput[i].checked = sel;
		}
	}
}

function openMsg(t){
	obj = document.getElementById('minipop');
	obj.href = '/inc/minipop.php?'+t;
	obj.onclick();
}

function openDetMsg(t){
	obj = document.getElementById('popdet');
	obj.href = '/pge/popdet.php?det='+t;
	obj.onclick();
}

function openBigMsg(t){
	obj = document.getElementById('bigpop');
	obj.href = '/inc/minipop.php?'+t;
	obj.onclick();
}

function openTouMsg(t){
	obj = document.getElementById('toupop');
	obj.href = '/inc/minipop.php?'+t;
	obj.onclick();
}

function openBigMsgWide(t){
	obj = document.getElementById('bigpopwide');
	obj.href = '/inc/minipop.php?'+t;
	obj.onclick();
}

function openCpop(t){
	obj = document.getElementById('cpop');
	obj.href = '/inc/minipop.php?'+t;
	obj.onclick();
}

function setHome()
{
   document.body.style.behavior='url(#default#homepage)';
   document.body.setHomePage('http://www.cornerstonesworld.com');
}


//////////////////////////////////// Preload Images

var imgFile = [
	'/img/lnbot.png',
	'/img/lnmid.gif',
	'/img/lntopopen.gif',
	'/img/rounddeflb.png',
	'/img/rounddeflm.gif',
	'/img/rounddeflt.png',
	'/img/rounddefmb.gif',
	'/img/rounddefmt.gif',
	'/img/rounddefrb.png',
	'/img/rounddefrm.gif',
	'/img/rounddefrt.png',
	'/img/tooltip_lb.png',
	'/img/tooltip_lm.png',
	'/img/tooltip_lt.png',
	'/img/tooltip_mb.png',
	'/img/tooltip_mm.png',
	'/img/tooltip_mt.png',
	'/img/tooltip_rb.png',
	'/img/tooltip_rm.png',
	'/img/tooltip_rt.png'
];

var imgObj = [];
for(var i=0; i<imgFile.length; i++) {
  imgObj[i] = new Image();
  imgObj[i].src = imgFile[i];
}



//////////////////////////////////// Clock

function UpdateClock(offsets) {
    if (clockID) {
        clearTimeout(clockID);
        clockID = 0;
    }
	
    var theClock = document.getElementById("clock");
    if (theClock) {
        var tDate = new Date;
		var localoff = (parseInt(tDate.getTimezoneOffset()) / 60) + 1;
        var seconds = addNil(tDate.getSeconds());
        var minutes = addNil(tDate.getMinutes());
		
		var h = tDate.getHours()+parseInt(localoff)+parseInt(offsets);
		if(h > 24) h = h - 24;
		if(h < 0) h = 24 + h;
		
        var timeString = "" + addNil(h) + ":" + minutes;
        theClock.innerHTML = timeString;
    }
    clockID = setTimeout("UpdateClock("+offsets+")", 10000);
    return true;
}

function addNil(val) {
    return val.toString().length == 1 ? "0" + val : val;
}

function StartClock(off) {
	var offsets = off;
    clockID = setTimeout("UpdateClock("+offsets+")", 1000);
}

function KillClock() {
    if (clockID) {
        clearTimeout(clockID);
        clockID = 0;
    }
}




//////////////////////////////////// HighSlide

hs.graphicsDir = '/inc/highslide/graphics/';
hs.outlineType = 'rounded-white';
hs.allowMultipleInstances = true;
hs.outlineWhileAnimating = true;
hs.showCredits = false;
hs.dimmingOpacity = 0;
hs.dimmingDuration = 0;
hs.expandDuration = 1;
hs.expandSteps = 1;
hs.restoreDuration = 1;
hs.restoreSteps = 1;
hs.allowHeightReduction = false;
hs.dragByHeading = false;
hs.preserveContent = false;
//hs.dimmingGeckoFix = true;

if (hs.addSlideshow) hs.addSlideshow({
	slideshowGroup: 'first-group',
	interval: 5000,
	repeat: false,
	useControls: true,
	fixedControls: 'fit',
	overlayOptions: {
		opacity: .8,
		position: 'bottom center',
		hideOnMouseOut: true
	}
});

hs.swfOptions = {
	version: "8",
	expressInstallSwfurl: "/inc/expressinstall.swf",
	flashvars: {},
	params: {},
	attributes: {}
};

hs.lang = {
   loadingText :     'Loading...',
   loadingTitle :    '',
   focusTitle :      '',
   fullExpandTitle : '',
   fullExpandText :  '',
   creditsText :     'Powered by <i>Highslide JS</i>',
   creditsTitle :    '',
   previousText :    '',
   previousTitle :   '',
   nextText :        '',
   nextTitle :       '',
   moveTitle :       '',
   moveText :        '',
   closeText :       '',
   closeTitle :      '',
   resizeTitle :     '',
   playText :        '',
   playTitle :       '',
   pauseText :       '',
   pauseTitle :      '',
   number :          'Picture %1/%2',
   restoreTitle :    ''
};


//////////////////////////////////// HS from flash
/*
function hsgal(hslinkid){
	hsobject = document.getElementById(hslinkid);
	hs.htmlExpand(hsobject,{objectType:'iframe',contentId:'hspop',align:'center',width:500,dimmingOpacity:0,preserveContent:false});
}
*/

function hsgal(hslinkid,lgalxml){
	var hsobject = document.getElementById(hslinkid);
	hs.htmlExpand(hsobject,{objectType:'swf',width:500,objectWidth:500,objectHeight:460,swfOptions:{version:'8',expressInstallSwfurl:null,flashvars:{xmlpath:lgalxml.replace('&','%26')},params:{},attributes:{}},contentId:'hspop',allowSizeReduction:false,targetX:'sgal -280px',targetY:'sgal -60px',dimmingOpacity:0})
}

function hsimg(hslinkid){
	/*var posx = hslinkid + " 30px";
	var posy = hslinkid + " 30px";*/
	var hsobject = document.getElementById(hslinkid);
	hs.expand(hsobject,{targetX:'sgal -280px',targetY:'sgal -60px',dimmingOpacity:0,preserveContent:false});
}


//////////////////////////////////// print ID
/*
function printID(obj) {
  var w = window.open('','newwin')
  w.document.write('<style media="print">.noPrint{display:none}</style>'+
'<body onLoad="window.focus(); window.print()">'+
document.getElementById(obj).innerHTML)+
'</body>')
  w.document.close()
}
*/


//////////////////////////////////// group B banners

var bbnum = 0;
var bbans
var totalbbans = 0;
var currentbban = 0;
var nextbban = 0;
var bbantimer

$(document).ready(function(){
	
	getbbans();
	
});

function startbbantimer(){
	bbantimer=setTimeout("setbban(nextbban,true)",4000);
}

function stopbbantimer(){
	clearTimeout(bbantimer);
}

function getbbans(){
	bbans = getElementsByClass('bban');
	totalbbans = bbans.length;
	if(totalbbans > 0){
		setbban(0,true);
	}
}

function getnextbban(){
	nextbban = currentbban + 1;
	if(nextbban >= totalbbans){
		nextbban = 0;
	}
}

function setbban(bbnum,withtimer){
	currentbban = bbnum;
	stopbbantimer();
	var bbanlist = document.getElementById("bbanlist" + bbnum);
	
	// show banner
	for(i=0; i<totalbbans; i++){
		bbans[i].style.display = "none";
	}
	var newbban = document.getElementById("bban" + bbnum);
	newbban.style.display = "";
	
	// activate row
	var actfullrow = getElementsByClass('bbanfullrowact');
	for(i=0; i<actfullrow.length; i++){
		actfullrow[i].className = "bbanfullrow";
	}
	var actbudgetrow = getElementsByClass('bbanbudgetrowact');
	for(i=0; i<actbudgetrow.length; i++){
		actbudgetrow[i].className = "bbanbudgetrow";
	}
	var actfullrow = getElementsByClass('bbanbasicrowact');
	for(i=0; i<actfullrow.length; i++){
		actfullrow[i].className = "bbanbasicrow";
	}
	
	var actrowclass = bbanlist.getAttribute('class');
	if(!actrowclass){actrowclass = bbanlist.getAttribute('className');}	//for IE
	
	if(actrowclass == "bbanfullrow"){
		bbanlist.className="bbanfullrowact";
	}
	if(actrowclass == "bbanbudgetrow"){
		bbanlist.className="bbanbudgetrowact";
	}
	if(actrowclass == "bbanbasicrow"){
		bbanlist.className="bbanbasicrowact";
	}
	
	getnextbban();
	if(withtimer == true){
		startbbantimer();
	}
}

function bbanover(bbnum){
	if(bbnum == currentbban){
		stopbbantimer();
	}else{
		setbban(bbnum, false);
	}
}

function bbanout(){
	/*
	var bbanlist = document.getElementById("bbanlist" + bbnum);
	var actrowclass = bbanlist.getAttribute('class');
	if(!actrowclass){actrowclass = bbanlist.getAttribute('className');}
	if(actrowclass == "bbanfullrowact"){
		bbanlist.className="bbanfullrow";
	}
	if(actrowclass == "bbanbudgetrowact"){
		bbanlist.className="bbanbudgetrow";
	}*/
	startbbantimer();
}

function bbanfullclick(obj){
	var objclass = obj.getAttribute('class');
	if(!objclass){objclass = obj.getAttribute('className');}
	if(objclass == "bbanfulltitle"){
		var allrows = getElementsByClass('bbanfullrow');
		for(i=0; i<allrows.length; i++){
			allrows[i].style.display = "";
		}
		var allactrows = getElementsByClass('bbanfullrowact');
		for(i=0; i<allactrows.length; i++){
			allactrows[i].style.display = "";
		}
		obj.className="bbanfulltitle_open";
	}
	if(objclass == "bbanfulltitle_open"){
		var allrows = getElementsByClass('bbanfullrow');
		for(i=0; i<allrows.length; i++){
			allrows[i].style.display = "none";
		}
		var allactrows = getElementsByClass('bbanfullrowact');
		for(i=0; i<allactrows.length; i++){
			allactrows[i].style.display = "none";
		}
		obj.className="bbanfulltitle";
	}
}

function bbanbudgetclick(obj){
	var objclass = obj.getAttribute('class');
	if(!objclass){objclass = obj.getAttribute('className');}
	if(objclass == "bbanbudgettitle"){
		var allrows = getElementsByClass('bbanbudgetrow');
		for(i=0; i<allrows.length; i++){
			allrows[i].style.display = "";
		}
		var allactrows = getElementsByClass('bbanbudgetrowact');
		for(i=0; i<allactrows.length; i++){
			allactrows[i].style.display = "";
		}
		obj.className="bbanbudgettitle_open";
	}
	if(objclass == "bbanbudgettitle_open"){
		var allrows = getElementsByClass('bbanbudgetrow');
		for(i=0; i<allrows.length; i++){
			allrows[i].style.display = "none";
		}
		var allactrows = getElementsByClass('bbanbudgetrowact');
		for(i=0; i<allactrows.length; i++){
			allactrows[i].style.display = "none";
		}
		obj.className="bbanbudgettitle";
	}
}

function bbanbasicclick(obj){
	var objclass = obj.getAttribute('class');
	if(!objclass){objclass = obj.getAttribute('className');}
	if(objclass == "bbanbasictitle"){
		var allrows = getElementsByClass('bbanbasicrow');
		for(i=0; i<allrows.length; i++){
			allrows[i].style.display = "";
		}
		var allactrows = getElementsByClass('bbanbasicrowact');
		for(i=0; i<allactrows.length; i++){
			allactrows[i].style.display = "";
		}
		obj.className="bbanbasictitle_open";
	}
	if(objclass == "bbanbasictitle_open"){
		var allrows = getElementsByClass('bbanbasicrow');
		for(i=0; i<allrows.length; i++){
			allrows[i].style.display = "none";
		}
		var allactrows = getElementsByClass('bbanbasicrowact');
		for(i=0; i<allactrows.length; i++){
			allactrows[i].style.display = "none";
		}
		obj.className="bbanbasictitle";
	}
}


//////////////////////////////////// LimitText

function limitText(limitField, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	}
}



//////////////////////////////////// Rounded corners

$(document).ready(function(){
	
	$(".roundnone").bind("mouseenter mouseleave",function(){
		$(this).toggleClass("rounddef");
	});
	
});

/*
var roundedfull = RUZEE.ShadedBorder.create({ corner:8, shadow:0,  border:1 });

$(document).ready(function(){
	
	roundedfull.render($('.rounded, .lightround'));
	
	$(".rounded").bind("mouseenter mouseleave",function(){
		$(this).toggleClass("shaded");
	});
	
});
*/



//////////////////////////////////// Tooltips

$(function() {
	
	$('.service, .iconprof, .profinfoact, .profinfoinact, .profinfodisabled, .quest').tooltip({
	track: true,
	delay: 0,
	showURL: false,
	showBody: " - ",
	fade: 0
	//fixPNG: true
	});
	
});



//////////////////////////////////// Check Checkboxes

function checkall(group){
	for(i = 0; i < group.length; i++){
		group[i].checked = true;
	}
}

function uncheckall(group){
	for(i = 0; i < group.length; i++){
		group[i].checked = false;
	}
}

function checkuncheck(what){
	$checkuncheckobject = document.getElementById(what);
	$checkuncheckobject.checked = $checkuncheckobject.checked=="" ? "true" : "";
}



//////////////////////////////////// Rating

function rating(r){
	
	var ratingact = getElementsByClass('ratingthumbact');
	for(i=0; i<ratingact.length; i++){
		ratingact[i].className='ratingthumb';
	}
	
	for(i=1; i<=r; i++){
		document.getElementById("rating"+i).className='ratingthumbact';
	}
	
}


//////////////////////////////////// Languages

$(document).ready(function(){
	
	$("div#lncont").bind("mouseleave",function(){
		hide("lnopen");
		$("table#lntop").removeClass("lnact");
	});
	
	$("table#lntop").bind("click",function(){
		showhide("lnopen");
		$(this).toggleClass("lnact");
	});
	
});

/////////////////////////////////// Search //$(this).attr('action');
$(document).ready(function(){
	$('#srchfrm').submit(function() {
		var str = $('#srchfrm').serialize();
		var path = '/inc/get.php';
		$.post(path, str,
			function(data){
				newpath = data;
				document.location.href=data;
			});
		return false;
	});
});


//////////////////////////////////// Profile info switcher

function profinfoclick(clickobj,what){
	hideclass('profinfocont');
	show('prof' + what);
	hideclass('profinfotitle');
	show('profinfotitle_' + what);
	var prevactobjs = getElementsByClass('profinfoact');
	for(i=0; i<prevactobjs.length; i++){
		prevactobjs[i].className='profinfoinact';
	}
	clickobj.className='profinfoact';
}



//////////////////////////////////// Show / Hide

function showhide(hidewhat){
	hideobject = document.getElementById(hidewhat);
	hideobject.style.display = hideobject.style.display=="none" ? "" : "none";
}

function show(showwhat){
	showobject = document.getElementById(showwhat);
	showobject.style.display = "";
}

function hide(hidewhat){
	hideobject = document.getElementById(hidewhat);
	hideobject.style.display = "none";
}

function showclass(whatclass){
	var objs = getElementsByClass(whatclass);
	for(i=0; i<objs.length; i++){
		objs[i].style.display = "";
	}
}

function setLng(ln){
	document.getElementById('cln').innerHTML = ln;	
}

function hideclass(whatclass){
	var objs = getElementsByClass(whatclass);
	for(i=0; i<objs.length; i++){
		objs[i].style.display = "none";
	}
}

function showhideclass(whatclass){
	var objs = getElementsByClass(whatclass);
	for(i=0; i<objs.length; i++){
		objs[i].style.display = objs[i].style.display=="none" ? "" : "none";
	}
}



//////////////////////////////////// Show / Hide Stylechange

function advsearchstyle(obj){
	obj.className = obj.className=="linkhide" ? "linkshow" : "linkhide";
}

function switchobjectclass(objid,class1,class2){
	obj = document.getElementById(objid);
	obj.className = obj.className == class1 ? class2 : class1;
}



//////////////////////////////////// Change Style

function changeclass(obj, newclass){
	document.getElementById(obj).className = newclass;
}



//////////////////////////////////// Get Elements by Class

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}



//////////////////////////////////// Fix IE6 Flickering

function fixIE6flicker(fix) {
	try {
		document.execCommand("BackgroundImageCache", false, fix);
	} catch(err) { }
}
fixIE6flicker(true);



//////////////////////////////////// Scroll to element

function ScrollToElement(obj){
	if(obj){
		theElement = document.getElementById(obj);
		
	  var selectedPosX = 0;
	  var selectedPosY = 0;
	              
	  while(theElement != null){
	    selectedPosX += theElement.offsetLeft;
	    selectedPosY += theElement.offsetTop;
	    theElement = theElement.offsetParent;
	  }
	                        		      
	 window.scrollTo(selectedPosX,selectedPosY);
	}
}



//////////////////////////////////// Register private or client

function changePrivateClient(){
	if (document.getElementById('selectwho').value == "client"){
		hide('regprivate');
		show('regclient');
		recap(0,'capdiv');
	} else {
		hide('regclient');
		show('regprivate');
		recap(0,'capdivp');
	}
}

function doDel(o) {
	var agree=confirm("Are you sure you wish to delete selected row?");
		if (agree) {
			var hd = document.getElementById('actbil');
 			hd.value = o;
			document.getElementById('boxAct').submit();
		}
		else
			return false ;	
}

////


function CreateBookmarkLink() {
	title = document.title;
	url = window.location.href;
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, ""); //Dont use until it's fixed
	//	alert('Dear Firefox user, please press CTRL+D to Bookmark this page!');
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}



