function FireFlash(SiteFile,SiteView){
    $('#webtext').css({'display':'block'});
    var flashvars = {};
	flashvars.preloaderColor="0xffffff";	
	flashvars.xmlDataPath= SiteFile;
	var params = {};
    var attributes = {};    
    swfobject.embedSWF(SiteView, "webtext", "800", "600", "9.0.0", flashvars, params, attributes);

	//var fo = new SWFObject(SiteView, "viewer", "800", "600", "7", "#181818");	
	//fo.addVariable("preloaderColor", "0xffffff");
	//fo.addVariable("xmlDataPath", SiteFile);	
	//fo.write("webtext");	
}
function EmbedFrame(SiteView){
	$('#webtext').html('<iframe src=\"'+SiteView+'\" width=\"800\" height=\"600\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"no\" scrolling=\"no\" style=\"border-width:0px; background:#FFF;\"></iframe>');
}
function GetPortFolio(fPart){
    if (fPart=='men'){
    	EmbedFrame('/Gallerymen/gallery.html');
        //window.open('http://www.southweststudios.co.uk/Gallerymen/gallery.html','Men','width=800,height=600');
    } else if (fPart=='women'){
    	EmbedFrame('/Gallerywomen/gallery.html');
		//window.open('http://www.southweststudios.co.uk/Gallerywomen/gallery.html','Women','width=800,height=600');
    } else if (fPart=='children'){
    	EmbedFrame('/Gallerykids/gallery.html');
        //window.open('http://www.southweststudios.co.uk/Gallerykids/gallery.html','men','width=800,height=600');
    } else if (fPart=='weddings'){
    	EmbedFrame('/Gallerywedds/gallery.html');
        //window.open('http://www.southweststudios.co.uk/Gallerywedds/gallery.html','Weddings','width=800,height=600');
    } else if (fPart=='groups'){
    	EmbedFrame('/Gallerygroups/gallery.html');
        //window.open('http://www.southweststudios.co.uk/Gallerygroups/gallery.html','Groups & Events','width=800,height=600');
    }
}

function SetChanged(token){
    if ($('#pagestatus').val()=='edit' || $('#pagestatus').val()=='add'){
       $('#pagestatus').val('changed');
    }
}

function GetotherPage(newUrl){
   window.location = newUrl;
}

function SetReferrer(){
    // If referrer cookie present skip it
    if (!GetCookie ('referrer')){  var temp; var cookie_ok=false; if (document.referrer=='' || !document.referrer){ temp='manual'; SetCookie('referrer',temp); cookie_ok=true; } else { temp=document.referrer; SetCookie('referrer',temp); cookie_ok=true; } if (cookie_ok){ jQuery.get("set"+"ref"+"er"+"rer.p"+"hp");  }
    }   
}

function SetCookie(cookieName,cookieValue,nDays) {
    // all cookies are deleted at closing browser/session
    var today = new Date();
    var expire = new Date();
    if (nDays===null || nDays===0){nDays=1;}
    expire.setTime(today.getTime() + 3600000*2*nDays);
    document.cookie = cookieName+'='+escape(cookieValue);
}	 
function GetCookie(check_name) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	for (i=0;i<a_all_cookies.length;i++){
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name ) {
			b_cookie_found = true;
			//we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )	{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			//break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ){
		return null;
	}
}				

function CountLeft(field, count, max) {
// if the length of the string in the input field is greater than the max value, trim it
if (field.value.length > max) {
  field.value = field.value.substring(0, max);
} else {
// calculate the remaining characters
count.value = max - field.value.length;
}
}

function checkTimeZone() {
    // current date and time of user
    var rightNow = new Date();
    var date5 = rightNow;
    // first januari 1st for this user
    var date1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);
    // find july 1st for this user
    var date2 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0);
    // convert januari 1st to GMT
    var temp = date1.toGMTString();
    var date3 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
    // convert july 1st to GMT 
    temp = date2.toGMTString();
    var date4 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
    // convert current time to GMT    
    temp = date5.toGMTString();
    var date6 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
    // find the difference in hours between januari 1 user and januari 1 GMT
    var hoursDiffStdTime = (date1 - date3) / (1000 * 60 * 60);
    // find the difference in hours between juli 1 user and juli 1 GMT 
    var hoursDiffDaylightTime = (date2 - date4) / (1000 * 60 * 60);
    // If the hours differ the user uses Daylight Saving Time
    if (hoursDiffDaylightTime>hoursDiffStdTime) { DstValidForThisUser=1;} else{ DstValidForThisUser=0;}
    // Calculate the minutes difference between user en GMT
    var minsDiffCurrentTime = Math.round((date5 - date6) / (1000 * 60));
    SetCookie("TimeZone",hoursDiffStdTime);
    SetCookie("DST_Difference",hoursDiffDaylightTime);
    SetCookie("DST_Used",DstValidForThisUser);
    SetCookie("Current_difference",minsDiffCurrentTime);
}
function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for (var iParam=0;iParam<aQueryString.length;iParam++){
      if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
} 
function getURLQuery(){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?"));
    strReturn = strQueryString.toUpperCase();
  }
  return unescape(strReturn);
} 

function AmountFormat(AmountField,DecPlaces){
     var newPrice=""; 
     var valPrices=$('#'+AmountField).val(); 
     var lenPrices=valPrices.length; 
     if (lenPrices===0){return};
     var strTemp =""; var chrAllowed="0123456789.,-"; 
     var dotcount=0; 
     var negnumber=0;
     for (i=lenPrices;i>=0;i--){ 
         if(chrAllowed.indexOf(valPrices.charAt(i)) != -1) { 
             if (valPrices.charAt(i)!='.' && valPrices.charAt(i)!=',') {
                     newPrice = valPrices.charAt(i) + newPrice;
                  if (valPrices.charAt(i)=='-'){
                     break;    
                  }
             } else { 
                  strTemp='.'; 
                  if (dotcount===0 && newPrice!==""){ 
                      newPrice=strTemp + newPrice; 
                      dotcount=1; 
                  } 
             } 
         } 
     }
     newPrice = parseFloat(newPrice).toFixed(DecPlaces); 
     if (newPrice==='NaN') { 
         newPrice="0"; 
     } 
     newPrice = parseFloat(newPrice).toFixed(DecPlaces); 
     if (newPrice!=valPrices){ 
         $('#'+AmountField).val(newPrice); 
         return; 
     } 
}

function EmailFormat(eField,msgWrong){
    if ($('#'+eField).val().length==0) {return true; }
    var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    if($('#'+eField).val().match(emailExp)){
       $('#lbl'+eField).css({'color':'black'});
       return true;
    } else {
       alert(msgWrong);
       $('#lbl'+eField).css({'color':'red'});
       return false;
    } 
}

function stringifyObj(o) {
var stringified = "";

if (typeof(o) == "object") {
     stringified = "{";
var first =true;

for (var key in o) {
if(!first) { stringified +=","; }
else { first =false; }
stringified +=(typeof(o[key]) == "object") ? stringifyObj(o[key]) :
'"' +key +'":"' +o[key] +'"';
}

stringified +="}";
}

return stringified;
}
function urlencode(str) {
return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}
