// HRISTO HRISTOV - Basic JS Scripts

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}

function trigger_effect(src_element,div_id, effect, first_img, second_img){
		Effect.toggle(div_id, effect, {duration: 0.4, beforeFinish:function(){
		image = src_element.getElementsByTagName('img')[0];
		image.src = image.src.match(first_img) ? second_img : first_img;
		}});
		return true;
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

function trim ( string ) {
	var i, numFirstChar = -1, numLastChar = -1;
	for ( i = 0; i < string.length; i ++ ) {
		if ( string.substring ( i, i + 1 ) != ' ' ) {
			numFirstChar = i;
			break;
		}
	}
	if ( numFirstChar == -1 )
		return "";
	for ( i = string.length; i >= 0; i -- ) {
		if ( string.substring ( i - 1, i ) != ' ' ) {
			numLastChar = i;
			break;
		}
	}
	return string.substring ( numFirstChar, numLastChar );
}

function isEmail(email) {
	var valid_email_address = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return valid_email_address.test(email)
}
function isPhoneNumber(phone) {
	var valid_phone_number=/^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$/;
	return valid_phone_number.test(phone)
}

function hasHTML(str) {
    if (str.match(/([\<])([^\>]{1,})*([\>])/i) == null) { return false; } else { return true; }
}

function pcase(str) {
	strlen = str.length
	jj = str.substring(0,1).toUpperCase()
	jj = jj + str.substring(1,strlen).toLowerCase()
	for (i = 2; i <= strlen; i++) {
		if (jj.charAt(i)==" ") {
			lefthalf = jj.substring(0,i+1)
			righthalf = jj.substring(i+1,strlen)
			righthalf = righthalf.substring(0,1).toUpperCase()+righthalf.substring(1,strlen)
			jj=lefthalf+righthalf
		}
	}
	return jj
}

function AutoResizeIFrm(ifrmobj) {
	if (document.getElementById) {
		var success = 0;
		var oFrame = ifrmobj; //document.getElementById("ifrm");
		if(oFrame.style.display=='none') {
			oFrame.style.height='0px';
			oFrame.style.display='inline';
		}
		var oLoading = document.getElementById('loading');
		if(oLoading) {
			oLoading.style.display='none';
		}
		// Mozilla solution
		if (oFrame.contentDocument) {
//			alert("id='" + oFrame.id + "' height='" + oFrame.contentDocument.height + "'");
			var height = oFrame.contentDocument.height;
//			if (height > 100) {
				oFrame.style.height = (height+2) + "px";
				success = 1;
//			}
			// IE solution
		} else if (navigator && navigator.userAgent && navigator.userAgent.indexOf("MSIE") != -1 && ifrmobj) {
			var oBody = ifrmobj.contentWindow.document.body;
			var height = oBody.scrollHeight + (oBody.offsetHeight - oBody.clientHeight);
//			alert("id='" + oFrame.id + "' height='" + ifrmobj.contentWindow.document.body.scrollHeight + "'");
//			if (height > 100) {
				oFrame.style.height = (height+2) + "px";
				success = 1;
//			}
		}
	}
	if(window.frameElement) {
		//alert("window.frameElement.id='"+window.frameElement.id+"'");
		parent.AutoResizeIFrm(window.frameElement);
	}
}

function clear_field(field,default_value) {
	if (field.value==default_value) {
		field.value=""
	}
}

function validate_quicksignup(obj_form) {
	obj_form.email.value=trim(obj_form.email.value)
	
	if (obj_form.email.value=="") {
		alert("Email is a required.");
		obj_form.email.focus();
		return false;
	} else if (!isEmail(obj_form.email.value)) {
		alert("Email must be a valid email address.");
		obj_form.email.focus();
		return false;
	}
	
	return true;
}

function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

